This file contains 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
var alien = { | |
name: "Pampam", | |
age: 3435, | |
sayHello: function () { | |
console.log("Hello"); | |
} | |
}; |
This file contains 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
function Alien(name) { | |
this.name = name; | |
} | |
console.dir(Alien); |
This file contains 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
var A = {}; | |
var B = Object.create(A); |
This file contains 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
var A = { name: "a" }; | |
var B = { dev: true}; | |
//var C = Object.assign(A,B); | |
// taki zapis podmieni nam obiekt A | |
//dlatego, że pierwszy argument to źródło kopiowania wszystkich innych | |
//zatem zróbmy tak: | |
var C = Object.assign({}, A,B); // Obiekt C wygląda tak: {name: "a", dev: true} |
This file contains 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
var greenAlien = { | |
sayHello: function() { | |
return `Hello, my name is ${ this.name }` | |
} | |
} | |
var redAlien = Object.create(greenAlien); | |
redAlien.fly = function() { | |
console.log('I can fly'); | |
} |
This file contains 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
const alien = { | |
sayHello () { | |
return `Hello, my name is ${ this.name }`; | |
} | |
}; | |
const createAlien = (name) => { | |
return Object.assign(Object.create(alien), { | |
name | |
}); | |
} |
This file contains 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
const alien = { | |
sayHello () { | |
return `Hello, my name is ${ this.name }`; | |
} | |
}; | |
const clark = Object.assign( | |
{}, | |
alien, | |
{name: 'Clark'} |
This file contains 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
var cat = { | |
getVoice: function() { | |
console.log("Miau miau"); | |
} | |
}; | |
cat.getVoice(); // Miau miau |
This file contains 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
function Cat(name) { | |
this.name = name; | |
this.catFeet = 4; | |
this.getVoice = function() { | |
console.log("Miau miau"); | |
}; | |
} | |
var filemon = new Cat("Filemon"); | |
var mruczek = new Cat("Mruczek"); |
This file contains 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
function New(func) { | |
//1. create empty object | |
var res = {}; | |
//2. set his [[Prototype]] (aka __proto__) to function property prototype | |
res.__proto__ = func.prototype; | |
//3. It makes the this variable point to the newly created object | |
func.call(res); |
OlderNewer