Skip to content

Instantly share code, notes, and snippets.

var animal = {
eats: true
};
var rabbit = {
jumps: true,
__proto__: animal
};
for (var key in rabbit) {
var animal = {
eats: true
};
var rabbit = {
jumps: true,
__proto__: animal
};
for (var key in rabbit) {
var rabbit = {foo: 'bar'};
rabbit.__proto__ = window;
console.log(rabbit.location) // call location object through window object
let owl = {
sayHello(str) {
return `Hello ${str} !`;
}
}
let winnie = {};
winnie.__proto__ = owl;
let donkey = {};
let animal = {},
rabbit = {};
Object.setPrototypeOf(rabbit, animal); // rabbit.__proto__ = animal
console.log(Object.getPrototypeOf(rabbit) === animal ) // true
var animal = {eats: true};
var rabbit = Object.create(animal); //rabbit.__proto__ = animal
console.log(rabbit.eats) //true
var data = Object.create(null);
data.text = "Hello!";
console.log(data.text); // Hello!
console.log(data.toString); // undefined
console.log(data.__proto__);
let animal = {
jumps: null
};
let rabbit = {
jumps: true
};
rabbit.__proto__ = animal;
console.log( rabbit.jumps ); // ? (1)
var animal = {
eat: function() {
this.full = true;
}
};
var rabbit = {
__proto__: animal
};
var animal = {
eats: true
};
function Rabbit(name) {
this.name = name;
//this.__proto__ = animal; won't work in IE10+
}
Rabbit.prototype = animal; //only object, primitives won't work