Last active
January 23, 2018 09:10
-
-
Save dankogai/743f918112abde5c9ce3f68646e0bb96 to your computer and use it in GitHub Desktop.
what `new Array(n)` does
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let newArray = (n) => { | |
let o = Object.create(null); | |
Object.setPrototypeOf(o, Array.prototype); | |
Object.defineProperty(o, 'length', {value:n}); | |
return o; | |
} | |
// let a = newArray(2); | |
// console.log((a).map) | |
// console.log((a).map($=>"hello")) | |
// console.log(Array.from(a).map($=>"hello")) | |
// for (let k in a) { console.log('a[' + k + '] = ', a[k]); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment