Özgün Bal
Software Developer, Javascript Enthusiast
Özgün Bal
github: /ozgunbal
mail: ozgunbal@gmail.com
medium: @ozgunbal
const obj = {}; // Object literal
const obj2 = new Object(); // Object constructorfrom Just Javascript - Dan Abramov and Maggie Appleton
from Just Javascript - Dan Abramov and Maggie Appleton
from Just Javascript - Dan Abramov and Maggie Appleton
const presenter = {
name: 'Özgün',
welcomeSpeech: function () {
console.log(`My name is ${this.name}`);
},
};function Presenter () {
this.name = name;
this.welcomeSpeech = function () {
console.log(`My name is ${this.name}`);
};
}const jsPresenter = new Presenter('Özgün');
jsPresenter instanceof Presenterfunction Stream (name) {
this.name = name;
}
Stream.prototype.hasPublicAccess = true;
Stream.prototype.play = function () {
console.log(`${this.name} has${this.hasPublicAccess ? ' ' : ' not '}public access...`)
};
const youtube = new Stream('Youtube');
youtube.play(); // Youtube has public access...
youtube.hasPublicAccess; // truefunction ITGuy(name) {
this.name = name;
this.department = "IT";
}
function Developer(name) {
ITGuy.call(this, name);
this.unit = "Software Development";
}
Developer.prototype = Object.create(ITGuy.prototype);
Developer.prototype.constructor = Developer;class ITGuy {
constructor(name) {
this.name = name;
this.department = "IT";
}
}
class Developer extends ITGuy {
constructor(name) {
super(name);
this.unit = "Software Development";
}
}function Furniture (type, color) {
this.type = type;
this.color = color;
this.paint = function (anotherColor) {
this.color = anotherColor;
}
}function WhiteGoods (type, color) {
this.type = type;
this.color = color;
}
WhiteGoods.prototype.paint = function (anotherColor) {
this.color = anotherColor;
};const multiplier = (mult = 2) => {
let count = 1;
return () => {
count *= mult;
return count;
}
}const StuffFactory = {
Stuff : function (stuffType) {
return Object.create(this.stuffs[stuffType]);
},
stuffs: {
whitegood: {
color: 'white',
electricity: true,
},
furniture: {
electricity: false,
},
},
}function extend (obj, mixin) {
return Object.assign(obj, mixin);
}
myMixins = {
paint: function (newColor) {
this.color = newColor;
},
}
function Furniture(type, color) {
this.type = type;
this.color = color;
}
function WhiteGoods(type, color) {
this.type = type;
this.color = color;
}
extend(Furniture.prototype, myMixins)
extend(WhiteGoods.prototype, myMixins);By Özgün Bal