__proto__
by Artem
JavaScript
'use strict';
const ObjectPrototype = {
get _PROTO_() {
return Object.getPrototypeOf(this);
}
}
function CustomArray(...args) {
args.forEach((arg, i) => {
this[i] = arg;
});
this.length = args.length;
}
CustomArray.prototype = Object.create(ObjectPrototype);
// CustomArray.prototype = Object.create(null);
CustomArray.prototype.forEach = cb => {
for (let i = 0; i < this.length; i++) {
cb(this[i], i, this);
}
}
CustomArray.prototype.constructor = CustomArray;
var arr = new CustomArray(1, 2, 3);
console.log('arr._PROTO_ ', arr._PROTO_);
// console.log('Object.getPrototypeOf(arr) ', Object.getPrototypeOf(arr));