Function 1: Object.create

这是一个很重要的改动,现在我们终于可以得到一个原型链干净的对象了。以前要创建一个类

  1. function Cat(name) {
  2. this.name   = name;
  3. this.paws   = 4;
  4. this.hungry = false;
  5. this.eaten  = [];
  6. }
  7. Cat.prototype = {
  8. constructor : Cat,
  9. play        : function () { this.hungry = true; return 'playing!'; },
  10. feed        : function (food) { this.eaten.push(food); this.hungry = false; },
  11. speak       : function () { return 'Meow'; }
  12. };

必须要分两步走,但是现在可以不必了

  1. var Dog = {
  2. name   : 'dog',
  3. paws   : 4,
  4. hungry : false,
  5. eaten  : null,
  6. play   : function () { this.hungry = true; return 'playing!'; },
  7. speak  : function () { return 'Woof!'; }
  8. };
  9. var dog = Object.create(Dog);

Object.create他还有第2个参数,是一个properties descriptor object ,关于这方面的详细解释,请看第2点。

另外:如果浏览器不支持Object.create,可以用这种方法代替

  1. if (typeof Object.create !== 'function') {
  2. Object.create = function (o) {
  3. function F() {}
  4. F.prototype = o;
  5. return new F();
  6. };
  7. }

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 2: Object.defineProperty

如果你想为一个对象定义属性,那么就必须my_dog.age = 2; 用这种方法。但是在ECMAScript5中,提供了更好的包装方法Object.defineProperty

Parameters:

1.对象引用

2.属性名

3.修饰对象

修饰对象中的定义如下:

 value: use this to set the value of a property. Defaults to undefined.

 writable: use this boolean to define whether this is a read-only variable. If it’s writable, it’s true. Defaults to false.

 configurable: use this boolean to define whether the type (value vs. method) of this property can be changed, or whether the property can be deleted. If it’s configurable, it’s true. Defaults to false.

 enumerable: use this boolean to define whether this property is included when the properties of the object are enumerated (a for-in loop or the keys method). Defaults to false.

 get: use this to define a custom getter method. Defaults to undefined.

 set: use this to define a custom setter method. Defaults to undefined.

Sample:

  1. var Dog = {
  2. name   : 'dog',
  3. paws   : 4
  4. };
  5. var dog = Object.create(Dog);
  6. Object.defineProperty(dog, 'age', {
  7. set : function (age) { this.humanYears = age * 7; },
  8. get : function () { return this.humanYears / 7; },
  9. enumerable : true
  10. });
  11. dog.age = 2;
  12. dog.humanYears; // 14

以上代码让age和humanYears保存了同步,如果你不想对外界暴露humanYears,可以这样使用闭包:

  1. Object.defineProperty(dog, 'age', (function () {
  2. var humanYears;
  3. return {
  4. set : function (age) { humanYears = age * 7; },
  5. get : function () { return humanYears / 7; },
  6. enumerable : true
  7. };
  8. }()));

当然,也可以用在Object.create方法上面

  1. var yourDog = Object.create(Dog, {
  2. age : {
  3. get : function () { /* . . . */ },
  4. set : function () { /* . . . */ },
  5. enumerable: true
  6. },
  7. gender : {
  8. value : 'female'
  9. }
  10. });

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 3: Object.defineProperties

当然,如果你想像Object.create方法那样一口气给对象加入很多属性的话,你可以用Object.defineProperties方法

  1. Object.defineProperties(dog, {
  2. age : {
  3. get : function () { /* . . . */ },
  4. set : function () { /* . . . */ },
  5. enumerable: true
  6. },
  7. gender : {
  8. value : 'female'
  9. }
  10. });

注意区别 Object.create和Object.defineProperties第一个参数的不同,Object.create是prototype,而Object.defineProperties是对象

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 4: Object.getOwnPropertyDescriptor

用途:得到一个属性的定义

  1. var person = { name : 'Joe' };
  2. Object.getOwnPropertyDescriptor(person, 'name'); // { configurable : true,enumerable : true, value : 'Joe&', writable : true }

但是这个函数只能适用于函数自身的对象,并不能取得原型链上的属性

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 5: Object.keys

用途:取得所有的属性名

  1. var horse = { name : 'Ed', age : 4, job : 'jumping', owner : 'Jim' };
  2. var horseKeys = Object.keys(horse); // ['name', 'age', 'job', 'owner'];

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 6: Object.getOwnPropertyNames

此函数功能基本和第5点相同,但是她可以取得所有的属性名,即使那个属性是不可枚取的(属性的enumerable =false,详细请参照第2点)

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

Function 7: Object.preventExtensions / Object.isExtensible

这个函数能把一个对象的属性锁住,让他不能扩展。

  1. var product = { name : 'Foobar', rating : 3.5 };
  2. Object.isExtensible(product); // true
  3. Object.preventExtentions(product);
  4. Object.isExtensible(product); // false
  5. product.price = '$10.00'; // doesn't work
  6. product.price; // undefined

但是仅仅只是不能增加属性,他的值仍然是可以改的,而且这个属性也能够被delete

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Chrome 6+

Function 8: Object.seal / Object.isSealed

Seal一个对象意味着你无法增加删除属性,也无法把已经定义好的属性值指向一个accessor (a method or

function),反过来也是一样

  1. var pet = { name : 'Browser', type : 'dog' };
  2. Object.seal(pet);
  3. pet.name = 'Oreo';
  4. pet.age = 2; // doesn't work
  5. pet.type = function () { /**/ }; // doesn't work
  6. delete pet.name; // doesn't work

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Chrome 6+

Function 9: Object.freeze / Object.isFrozen

freeze一个对象,意味着你不能通过任何手段修改对象内容,他变成了完全只读的

  1. var obj = { greeting : 'Hi!' };
  2. Object.freeze(obj);
  3. Object.isFrozen(obj); // true

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Chrome 6+

Function 10: Array.isArray

很显然,这是一个判断是否是数组的函数

  1. var names = ['Collis', 'Cyan'];
  2. Array.isArray(names); // true

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Safari 5

○ Chrome 5+

○ Opera 10.5+

Function 11: Date.prototype.toJSON

提供了从Date类型转成json的方法。

  1. new Date().toJSON(); // "2010-12-06T16:25:40.040Z"

Function 12: Function.prototype.bind

你会发现这个函数的功能和下面的很相似

  1. var arr1 = ['1', '2', '3'],
  2. arr2 = ['4', '5', '6'];
  3. // 等同于arr1.push(arr2);
  4. Array.prototype.push.apply(arr1, arr2);
  5. alert(arr1);

bind和上面的不同之处在于apply是直接执行的,而bind只是绑定函数内部的this,并且将函数返回

  1. var tooltip = { text: 'Click here to . . . ' },
  2. overlay = { text: 'Please enter the number of attendees' };
  3. function showText () {
  4. // really, do something more useful here
  5. alert(this.text);
  6. }
  7. tooltip.show = showText.bind(tooltip);
  8. tooltip.show();
  9. overlay.show = showText.bind(overlay);
  10. overlay.show();

Browser Support

○ Firefox 4

○ Internet Explorer 9

○ Chrome 7+

Function 13: Date.now()

大致这个函数就是等同于new Date().getTime() or +new Date,不是什么大的改动

Function 14: Object.getPrototypeOf

这个函数提供了从通过Object.create得到的对象中提取原型的方法,当然,如果这个对象是通过老的new

function的方法创造出来的,那也可以通过这个方法得到原型

  1. var Dog = {
  2. name : 'dog',
  3. paws : 4,
  4. hungry : false,
  5. speak : function () { return 'Woof!'; }
  6. };
  7. var dog = Object.create(Dog);
  8. // true
  9. alert(Object.getPrototypeOf(dog) === Dog);
  10. // 老方法判断
  11. function Cat() {}
  12. // true
  13. alert(Object.getPrototypeOf(new Cat()) === Cat.prototype);

Function 15: String.prototype.trim

用来去除字符串两边的空格

  1. var origin = " foo ";
  2. document.write(origin.trim());

Function 16: Array.prototype.indexOf

这个函数用来返回查找的对象在数组中第一次出现的index

他有两个参数,第一个参数是要查找的对象,第二个参数是查找的起始位置

  1. var array = [2, 5, 9];
  2. var index = array.indexOf(2);
  3. // index is 0
  4. index = array.indexOf(7);
  5. // index is -1
  6. var element = 5;
  7. var indices = [];
  8. var idx = array.indexOf(element);
  9. while (idx != -1) {
  10. indices.push(idx);
  11. idx = array.indexOf(element, idx + 1);
  12. }

当然如果浏览器没有支持indexOf,你可以用以下方法实现

  1. if (!Array.prototype.indexOf) {
  2. Array.prototype.indexOf = function(searchElement /*, fromIndex */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (len === 0)
  9. return -1;
  10. var n = 0;
  11. if (arguments.length > 0) {
  12. n = Number(arguments[1]);
  13. if (n !== n)
  14. n = 0;
  15. else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
  16. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  17. }
  18. if (n >= len)
  19. return -1;
  20. var k = n >= 0
  21. ? n : Math.max(len - Math.abs(n), 0);
  22. for (; k < len; k++) {
  23. if (k in t && t[k] === searchElement)
  24. return k;
  25. }
  26. return -1;
  27. };
  28. }

Function 17: Array.prototype.lastIndexOf

用法和16相似,取得最后一次出现的index

如果浏览器没有实现此方法,你可以通过这种方式实现

  1. if (!Array.prototype.indexOf) {
  2. Array.prototype.indexOf = function(searchElement /*, fromIndex */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (len === 0)
  9. return -1;
  10. var n = 0;
  11. if (arguments.length > 0) {
  12. n = Number(arguments[1]);
  13. if (n !== n)
  14. n = 0;
  15. else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
  16. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  17. }
  18. if (n >= len)
  19. return -1;
  20. var k = n >= 0
  21. ? n : Math.max(len - Math.abs(n), 0);
  22. for (; k < len; k++) {
  23. if (k in t && t[k] === searchElement)
  24. return k;
  25. }
  26. return -1;
  27. };
  28. }
  29. Function 17: Array.prototype.lastIndexOf
  30. 用法和16相似,取得最后一次出现参数的index
  31. 如果浏览器没有实现此方法,你可以通过这种方式实现
  32. if (!Array.prototype.lastIndexOf) {
  33. Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) {
  34. "use strict";
  35. if (this === void 0 || this === null)
  36. throw new TypeError();
  37. var t = Object(this);
  38. var len = t.length >>> 0;
  39. if (len === 0)
  40. return -1;
  41. var n = len;
  42. if (arguments.length > 0) {
  43. n = Number(arguments[1]);
  44. if (n !== n)
  45. n = 0;
  46. else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0))
  47. n = (n > 0 || -1) * Math.floor(Math.abs(n));
  48. }
  49. var k = n >= 0
  50. ? Math.min(n, len - 1)
  51. : len - Math.abs(n);
  52. while (k >= 0) {
  53. if (k in t && t[k] === searchElement)
  54. return k;
  55. }
  56. return -1;
  57. };
  58. }

Function 18: Array.prototype.every

对于数组中的每一项都执行某个callback function,这个function的参数为当前数组元素,当前元素index,整个数组。当function中返回为false的时候,停止循环数组。仅当返回为true的时候继续循环

  1. function isBigEnough(element, index, array) {
  2. return (element >= 10);
  3. }
  4. var passed = [12, 5, 8, 130, 44].every(isBigEnough);
  5. // passed is false
  6. passed = [12, 54, 18, 130, 44].every(isBigEnough);
  7. // passed is true

当浏览器没有实现此方法时,可以用以下方式代替

  1. if (!Array.prototype.every) {
  2. Array.prototype.every = function(fun /*, thisp */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. var thisp = arguments[1];
  11. for (var i = 0; i < len; i++) {
  12. if (i in t && !fun.call(thisp, t[i], i, t))
  13. return false;
  14. }
  15. return true;
  16. };
  17. }

Function 19: Array.prototype.some

大致意思和every有些相似,当数组中有一个元素符合要求,就会返回true。所以callback中,一旦返回true,就不再循环,返回false则继续循环。

  1. function isBigEnough(element, index, array) {
  2. return (element >= 10);
  3. }
  4. var passed = [2, 5, 8, 1, 4].some(isBigEnough);
  5. // passed is false
  6. passed = [12, 5, 8, 1, 4].some(isBigEnough);
  7. // passed is true

当浏览器不支持的时候,你可以用以下代码代替

  1. if (!Array.prototype.some) {
  2. Array.prototype.some = function(fun /*, thisp */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. var thisp = arguments[1];
  11. for (var i = 0; i < len; i++) {
  12. if (i in t && fun.call(thisp, t[i], i, t))
  13. return true;
  14. }
  15. return false;
  16. };
  17. }

Function 20: Array.prototype.forEach

此函数对数组的所有元素循环执行一个callback function

  1. function printElt(element, index, array) {
  2. print("[" + index + "] is " + element); // assumes print is already defined
  3. }
  4. [2, 5, 9].forEach(printElt);
  5. // Prints:
  6. // [0] is 2
  7. // [1] is 5
  8. // [2] is 9

当浏览器没有实现的时候,你可以通过如下方法代替

  1. if (!Array.prototype.forEach) {
  2. Array.prototype.forEach = function(fun /*, thisp */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. var thisp = arguments[1];
  11. for (var i = 0; i < len; i++) {
  12. if (i in t)
  13. fun.call(thisp, t[i], i, t);
  14. }
  15. };
  16. }

Function 21: Array.prototype.map

循环数组每个元素,用于执行callback,之后返回循环结果作为一个新数组,而原数组不变.

Sample1:

  1. function makePseudoPlural(single) {
  2. return single.replace(/o/g, "e");
  3. }
  4. var singles = ["foot", "goose", "moose"];
  5. var plurals = singles.map(makePseudoPlural);
  6. // plurals is ["feet", "geese", "meese"]
  7. // singles is unchanged<span style="white-space: normal;"> </span>

Sample2

  1. var numbers = [1, 4, 9];
  2. var roots = numbers.map(Math.sqrt);
  3. // roots is now [1, 2, 3]
  4. // numbers is still [1, 4, 9]
 

如果浏览器没有实现,则可以用如下方法代替

  1. if (!Array.prototype.map) {
  2. Array.prototype.map = function(fun /*, thisp */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. var res = new Array(len);
  11. var thisp = arguments[1];
  12. for (var i = 0; i < len; i++) {
  13. if (i in t)
  14. res[i] = fun.call(thisp, t[i], i, t);
  15. }
  16. return res;
  17. };

Function 22: Array.prototype.filter

从数组中筛选出符合callback条件的元素,如果callback中返回true,则此元素会被加入到新数组中

  1. function isBigEnough(element, index, array) {
  2. return (element >= 10);
  3. }
  4. // 12, 130, 44
  5. var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);

如果浏览器没有实现,则可以用如下方式代替:

  1. if (!Array.prototype.filter) {
  2. Array.prototype.filter = function(fun /*, thisp */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. var res = [];
  11. var thisp = arguments[1];
  12. for (var i = 0; i < len; i++) {
  13. if (i in t) {
  14. var val = t[i]; // in case fun mutates this
  15. if (fun.call(thisp, val, i, t))
  16. res.push(val);
  17. }
  18. }
  19. return res;
  20. };
  21. }

Function 23: Array.prototype.reduce

这个函数有两个参数,第一个为callback function,第二个为初始值。

Callback function的格式为:

.reduce(function(previousValue, currentValue, index, array){ // ...})

如果没有设置初始值, previousValue从第一个元素开始, currentValue从第二个元素开始循环。
总共循环Array.prototype.length – 1次。
如果设置了初始值,previousValue从初始值开始,currentValue从第一个元素开始循环。
总共循环Array.prototype.length次。
最后返回最后一次callback function调用的结果.
Sample:
  1. var total = [0, 1, 2, 3].reduce(function(a, b){ return a + b; });
  2. // total == 6
  3. var flattened = [[0, 1], [2, 3], [4, 5]].reduce(function(a, b) {
  4. return a.concat(b);
  5. });
  6. // flattened is [0, 1, 2, 3, 4, 5]
 

如果浏览器没有实现,则可用以下代码代替

  1. if (!Array.prototype.reduce) {
  2. Array.prototype.reduce = function(fun /*, initialValue */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof fun !== "function")
  9. throw new TypeError();
  10. // no value to return if no initial value and an empty array
  11. if (len == 0 && arguments.length == 1)
  12. throw new TypeError();
  13. var k = 0;
  14. var accumulator;
  15. if (arguments.length >= 2) {
  16. accumulator = arguments[1];
  17. } else {
  18. do {
  19. if (k in t) {
  20. accumulator = t[k++];
  21. break;
  22. }
  23. // if array contains no values, no initial value to return
  24. if (++k >= len)
  25. throw new TypeError();
  26. } while (true);
  27. }
  28. while (k < len) {
  29. if (k in t)
  30. accumulator = fun.call(undefined, accumulator, t[k], k, t);
  31. k++;
  32. }
  33. return accumulator;
  34. };
  35. }

Function 24: Array.prototype.reduceRight

这个函数有两个参数,第一个为callback function,第二个为初始值。

Callback function的格式为:

.reduce(function(previousValue, currentValue, index, array){
// ...
})
如果没有设置初始值, previousValue从最后一个元素开始, currentValue从倒数第二个元素开始循环。
总共循环Array.prototype.length – 1次。
如果设置了初始值,previousValue从初始值开始,currentValue从最后一个元素开始循环。
总共循环Array.prototype.length次。
最后返回最后一次callback function调用的结果.
Sample:
  1. var total = [0, 1, 2, 3].reduceRight(function(a, b) { return a + b; });
  2. //total == 6
  3. var flattened = [[0, 1], [2, 3], [4, 5]].reduceRight(function(a, b) {
  4. return a.concat(b);
  5. }, []);
  6. // flattened is [4, 5, 2, 3, 0, 1]
 如果浏览器没有实现,则可以用如下代码代替
  1. if (!Array.prototype.reduceRight) {
  2. Array.prototype.reduceRight = function(callbackfn /*, initialValue */) {
  3. "use strict";
  4. if (this === void 0 || this === null)
  5. throw new TypeError();
  6. var t = Object(this);
  7. var len = t.length >>> 0;
  8. if (typeof callbackfn !== "function")
  9. throw new TypeError();
  10. // no value to return if no initial value, empty array
  11. if (len === 0 && arguments.length === 1)
  12. throw new TypeError();
  13. var k = len - 1;
  14. var accumulator;
  15. if (arguments.length >= 2) {
  16. accumulator = arguments[1];
  17. } else {
  18. do {
  19. if (k in this) {
  20. accumulator = this[k--];
  21. break;
  22. }
  23. // if array contains no values, no initial value to return
  24. if (--k < 0)
  25. throw new TypeError();
  26. } while (true);
  27. }
  28. while (k >= 0) {
  29. if (k in t)
  30. accumulator = callbackfn.call(undefined, accumulator, t[k], k, t);
  31. k--;
  32. }
  33. return accumulator;
  34. };
  35. }

ECMASCRIPT5新特性(转载)的更多相关文章

  1. ECMAScript5新特性总结

    虽然ECMAScript5早就成为标准推出来了,但之前因为一直用的是ECMAScript3,并且工作中总是要求兼容IE的低版本,所以用的比较少.如今市场上大多数浏览器都能兼容ECMAScript5(I ...

  2. Oralce 11g新特性 转载

    Oracle 11g于2007年7月11日美国东部时间11时(北京时间11日22时)正式发布,11g是甲骨文公司30年来发布的最重要的数据库版本,根据用户的需求实现了信息生命周期管理(Informat ...

  3. 基于webpack使用ES6新特性(转载)

    本文转载自: http://www.tuicool.com/articles/vye2ea6

  4. ECMAScript5新特性之获取对象特有的属性

    'use strict'; // 父类 function Fruit(){ } Fruit.prototype.name = '水果'; // 子类 function Apple(desc){ thi ...

  5. ECMAScript5新特性之isFrozen、freeze

    对象被冻结后: 1 不能添加属性. 2 不能删除属性. 3 不能修改属性.(赋值) 4 不能修改属性描述符.(会抛异常) var fruit = { name : '苹果', desc : '红富士' ...

  6. ECMAScript5新特性之isSealed、seal

    封闭对象后: 1 不能增加属性. 2 不能删除属性. 3 可以修改属性.(赋值) 4 不能修改属性描述符.(抛异常) var fruit = { name : '苹果', desc : '红富士' } ...

  7. ECMAScript5新特性之Object.isExtensible、Object.preventExtensions

    阻止对象扩展后: 1 不能添加属性. 2 可以修改属性的值. 3 可以删除属性. 4 可以修改属性描述符. var fruit = { name : '苹果', desc : '红富士' }; // ...

  8. Atitit js版本es5 es6新特性

    Atitit js版本es5 es6新特性 Es5( es5 其实就是adobe action script的标准化)1 es6新特性1 Es5( es5 其实就是adobe action scrip ...

  9. 使用示例带你提前了解 Java 9 中的新特性

    使用示例带你提前了解 Java 9 中的新特性 转载来源:https://juejin.im/post/58c5e402128fe100603cc194 英文出处:https://www.journa ...

随机推荐

  1. 如何增强ArcGIS插值图出图效果

    如何增强ArcGIS插值图出图效果 by 李远祥 在一些科研领域,经常会遇到使用插值的方式进行处理,并生成最终的插值图.插值图在ArcGIS里面非常容易生成,只要具备了采用点数据,通过ArcToolB ...

  2. 【craps赌博游戏】

    /* cpaps赌博游戏 说明: 一个简单的赌博游戏,游戏规则如下:玩家掷两个骰子,点数为1到6,如果第一次点数和为7或11,则玩家胜,如果点数和为2.3 或12,则玩家输,如果和 为其它点数,则记录 ...

  3. Weex系列二、显示图片

    上次我们创建了一个简单的Weex的demo. 一.常用的类 WXSDKEngine:SDK开放的绝大多数接口都在此有声明. WXLog: 用来打印日志. WXDebugTool: weex提供的对外调 ...

  4. Java 重写hashCode 方法和equals方法

    package Container; import java.util.HashSet; import java.util.Iterator; /* Set 元素是无序的(存入和取出的顺序不一定一致) ...

  5. jquery实现横向导航

    <!doctype html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. D. Jzzhu and Numbers

    这就是这个题目的意思,真的感觉这个思想是太神奇了,我这种菜逼现在绝壁想不到这样的证明的过程的,还有就是这个题的推道过程,以下思路纯属借鉴卿学姐的,还是自己太菜了,,,, 讲道理这种问题我真的想不到用容 ...

  7. 不惧面试:HTTP协议(3) - Cookie

    v博客前言 先交代下背景,写这个系列的原因是总结自己遇到的面试题以及可能遇到的题目,更重要的是,今年定的目标是掌握网络这一块的知识点,先是搞懂HTTP协议,然后是TCP/IP协议,再就是WCF如何运用 ...

  8. 解决CSS中float:left后需要clear:both清空

    现在,大部分的横排导航都是通过 ul -> li *n -> a 来实现的.具我所知,要达到这种效果,有几种方法可以实现. 1.传统处理方式: li {float:left;}/*这样,对 ...

  9. Javascript正则表达式(上)

    正则表达式一般用于验证客户端的用户输入,而服务器端的PHP.ASP.NET等脚本无须再进行验证,节约了后台开销. 1.两种创建方法 var box=new RegExp("Box" ...

  10. 配置apache

    1. 修改httpd.conf文件 # vi  /usr/local/apache/conf/httpd.conf 1) 设置根目录的路径 根目录是指Apache存放配置文件和日志文件的目录,配置参数 ...