Skip to content

Instantly share code, notes, and snippets.

function Cat(name) {
this.name = name;
}
Cat.prototype.getVoice = function() {
console.log("Miau miau");
};
Cat.prototype.catFeet = 4;
var numberOfCats = 1000000;
var arrayOfCats = [];
function Cat(name) {
this.name = name;
this.catFeet = 4;
this.getVoice = function() {
console.log("Miau miau");
};
}
var numberOfCats = 1000000;
var arrayOfCats = [];
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);
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");
var cat = {
getVoice: function() {
console.log("Miau miau");
}
};
cat.getVoice(); // Miau miau
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}
const alien = {
sayHello () {
return `Hello, my name is ${ this.name }`;
}
};
const clark = Object.assign(
{},
alien,
{name: 'Clark'}
const alien = {
sayHello () {
return `Hello, my name is ${ this.name }`;
}
};
const createAlien = (name) => {
return Object.assign(Object.create(alien), {
name
});
}
var greenAlien = {
sayHello: function() {
return `Hello, my name is ${ this.name }`
}
}
var redAlien = Object.create(greenAlien);
redAlien.fly = function() {
console.log('I can fly');
}
var A = {};
var B = Object.create(A);