Skip to content

Instantly share code, notes, and snippets.

View Katerina198b's full-sized avatar

Ekaterina Zakharenkova Katerina198b

  • Warsaw
View GitHub Profile
//cat.js
(function () {
const name = "Barry";
const getName = () => name;
const setName = (newName) => name = newName;
CAT_API = {getName, setName}
})();
//human.js
const callCat = () => `kitty kitty kitty, come here, ${CAT_API.getName()}`
//cat.js
CAT_API = function () {
const name = "Barry";
const getName = () => name;
const setName = (newName) => name = newName;
return {getName, setName}
})();
//human.js
const callCat = () => `kitty kitty kitty, come here, ${CAT_API.getName()}`
const createUser = ({ userName, avatar }) => ({
userName,
avatar,
setUserName(userName) {
this.userName = userName;
}
});
const IngredientList = ({list}) => (
React.createElement('ul', null,
list.msp((ingredient, i) => React.createElement('li', {key: i}, ingredient))
)
);
const Ingredients = React.createFactory(IngredientList);
render(
Ingredients({list}),
//without pattern
class Cat {
constructor(name, size, color, tailLength, character) {
this.size = size;
this.color = color;
this.name = name;
this.tailLength = tailLength;
this.character = character;
}
}
class Developer {
askQuestions() {
console.log('Asking about design patterns!')
}
}
class CommunityExecutive {
askQuestions() {
console.log('Asking about community building')
}
class Restaurant {
getBurger() {
return new Burger();
}
getIceCream() {
return new IceCream();
}
}
const cat = {
name: 'Snowball',
talk() {
console.log('Мяу');
}
};
const instance1 = cat;
const instance2 = cat;
console.log(instance1 === instance2) //true
const cat = {
name: 'Snowball',
talk() {
console.log('Мяу');
},
getInstance() {
return this;
}
}
const instance1 = cat.getInstance()
function bind(func, context) {
return function() {
return func.apply(context, arguments);
};
}