Skip to content

Instantly share code, notes, and snippets.

View sevperez's full-sized avatar

Severin Perez sevperez

View GitHub Profile
var products = {
"widget": 400,
"gear": 80,
"crank": 375,
"lever": 870,
};
var otherProducts = Object.create(products);
otherProducts["wheel"] = 210;
var products = {
"widget": 400,
"gear": 80,
"crank": 375,
"lever": 870,
};
var otherProducts = Object.create(products);
otherProducts["wheel"] = 210;
// prototypes0.js
var obj = {};
console.log(obj.toString());
// Logs: [object Object]
// prototypes1.js
var obj = {};
console.log(Object.getPrototypeOf(obj));
/* Logs:
{
constructor: ƒ Object(),
// prototypes1a.js
var obj = {};
obj.toString = function() {
console.log("I'm an object!");
};
obj.toString();
// Logs: "I'm an object!"
// prototypes2.js
var House = {
ringDoorbell: function() {
console.log("ding dong!");
},
describe: function() {
console.log(this.owner + "'s house has " + this.rooms + " rooms.");
}
// prototypes3.js
var House = {
ringDoorbell: function() {
console.log("ding dong!");
},
describe: function() {
console.log(this.owner + "'s house has " + this.rooms + " rooms.");
}
// prototypes4.js
var House = {
ringDoorbell: function() {
console.log("ding dong!");
},
describe: function() {
console.log(this.owner + "'s house has " + this.rooms + " rooms.");
}
// prototypes5.js
function crawlPrototypeChain(obj) {
console.log("-----------------");
console.log("Object: ", obj);
console.log("Own Properties: ", Object.getOwnPropertyNames(obj));
var objPrototype = Object.getPrototypeOf(obj);
if (objPrototype) {
crawlPrototypeChain(objPrototype);
function Robot(name, job) {
this.name = name;
this.job = job;
this.introduce = function() {
console.log("Hi! I'm " + this.name + ". My job is " + this.job + ".");
};
}
function AI(name, job, intelligenceLevel) {