Skip to content

Instantly share code, notes, and snippets.

@dankogai
Last active January 23, 2018 09:10
Show Gist options
  • Save dankogai/743f918112abde5c9ce3f68646e0bb96 to your computer and use it in GitHub Desktop.
Save dankogai/743f918112abde5c9ce3f68646e0bb96 to your computer and use it in GitHub Desktop.
what `new Array(n)` does
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