Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const DOM = (() => {
- const privateData = new WeakMap()
- class DOM{
- constructor(name, count){
- privateData.set(this, {count, name})
- }
- getCount(){
- return privateData.get(this).count
- }
- incCount(num){
- const c = privateData.get(this).count
- privateData.set(this, {
- ...privateData.get(this),
- count:c + num
- })
- }
- }
- return DOM
- })();
- const dom = new DOM("a" , 5)
- console.log(dom.getCount())
- dom.incCount(2)
- console.log(dom.getCount())
- const west = {
- name: "west",
- analogy:"aaa"
- }
- const getPropValue = (object, text ="") =>
- text
- .split(".")
- .reduce((acc,val) => {
- if(!val || !acc[val]) return acc
- return acc[val]
- }, object)
- const getName = west => getPropValue(west, "west.name")
- const analogy = west => getPropValue(west, "west.analogy")
- const age = west => getPropValue(west, "west.age")
- const composition = (selectors, transformation) => {
- return input => {
- const dep = selectors.reduce((acc,val) => {
- acc.push(val(input))
- return acc
- }, [])
- return transformation(...dep)
- }
- }
- const manchester = composition(
- [getName, analogy, age],
- (name, analgoy) => `${name} ${analgoy}`
- )(west)
- console.log(manchester)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement