Skip to content

Instantly share code, notes, and snippets.

var alien = {
name: "Pampam",
age: 3435,
sayHello: function () {
console.log("Hello");
}
};
function Alien(name) {
this.name = name;
}
console.dir(Alien);
var A = {};
var B = Object.create(A);
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}
var greenAlien = {
sayHello: function() {
return `Hello, my name is ${ this.name }`
}
}
var redAlien = Object.create(greenAlien);
redAlien.fly = function() {
console.log('I can fly');
}
const alien = {
sayHello () {
return `Hello, my name is ${ this.name }`;
}
};
const createAlien = (name) => {
return Object.assign(Object.create(alien), {
name
});
}
const alien = {
sayHello () {
return `Hello, my name is ${ this.name }`;
}
};
const clark = Object.assign(
{},
alien,
{name: 'Clark'}
var cat = {
getVoice: function() {
console.log("Miau miau");
}
};
cat.getVoice(); // Miau miau
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");
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);