你不知道的Array.from
Created|Updated
|Word count:303|Reading time:1min|Post View:
Array.from
可参考 MDN 里的 Array.from
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/from
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| var obj = { 0:1, 1:2, 2:3, length:3, length:4, length:0, push:[].push }; obj -> 伪类 ->类似于数组的一种伪类型 -> 不是JS类型 var newArr = Array.from(obj); console.log(newArr);
console.log(newArr.length); obj.push(4); console.log(obj);
|
Funny reference val
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| `function Array Object -> 引用值 ->Object.prototype`; var obj1 = {}; obj1.a = 1; var newObj = new Object(obj1); console.log(newObj === obj1);
var arr1 = [1, 2, 3, 4]; console.log(new Object(arr1));
var arr = []; arr.a = 1; var newarr = new Array(arr); console.log(newarr == arr);
var str = '123'; console.log(str.__proto__);
var a = 1; var newA = new Number(a); console.log(a == newA); console.log(a === newA);
|
Object
1 2 3 4 5 6 7 8 9 10 11 12
| var obj ={ a:1, b:2, c:3 } Object.defineProperty(obj,'b'{ enumerable:false })
console.log(Object.keys(obj));
console.log(Object.getOwnPropertyNames(obj));
|