This file contains hidden or 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
//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()}` |
This file contains hidden or 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
//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()}` |
This file contains hidden or 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 createUser = ({ userName, avatar }) => ({ | |
userName, | |
avatar, | |
setUserName(userName) { | |
this.userName = userName; | |
} | |
}); |
This file contains hidden or 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 IngredientList = ({list}) => ( | |
React.createElement('ul', null, | |
list.msp((ingredient, i) => React.createElement('li', {key: i}, ingredient)) | |
) | |
); | |
const Ingredients = React.createFactory(IngredientList); | |
render( | |
Ingredients({list}), |
This file contains hidden or 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
//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; | |
} | |
} |
This file contains hidden or 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
class Developer { | |
askQuestions() { | |
console.log('Asking about design patterns!') | |
} | |
} | |
class CommunityExecutive { | |
askQuestions() { | |
console.log('Asking about community building') | |
} |
This file contains hidden or 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
class Restaurant { | |
getBurger() { | |
return new Burger(); | |
} | |
getIceCream() { | |
return new IceCream(); | |
} | |
} |
This file contains hidden or 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 cat = { | |
name: 'Snowball', | |
talk() { | |
console.log('Мяу'); | |
} | |
}; | |
const instance1 = cat; | |
const instance2 = cat; | |
console.log(instance1 === instance2) //true |
This file contains hidden or 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 cat = { | |
name: 'Snowball', | |
talk() { | |
console.log('Мяу'); | |
}, | |
getInstance() { | |
return this; | |
} | |
} | |
const instance1 = cat.getInstance() |
This file contains hidden or 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 bind(func, context) { | |
return function() { | |
return func.apply(context, arguments); | |
}; | |
} |