Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. const DOM = (() => {
  2. const privateData = new WeakMap()
  3. class DOM{
  4. constructor(name, count){
  5. privateData.set(this, {count, name})
  6. }
  7.  
  8. getCount(){
  9. return privateData.get(this).count
  10. }
  11. incCount(num){
  12. const c = privateData.get(this).count
  13. privateData.set(this, {
  14. ...privateData.get(this),
  15. count:c + num
  16. })
  17. }
  18. }
  19.  
  20. return DOM
  21. })();
  22.  
  23.  
  24. const dom = new DOM("a" , 5)
  25.  
  26. console.log(dom.getCount())
  27. dom.incCount(2)
  28.  
  29. console.log(dom.getCount())
  30.  
  31.  
  32. const west = {
  33. name: "west",
  34. analogy:"aaa"
  35. }
  36.  
  37. const getPropValue = (object, text ="") =>
  38. text
  39. .split(".")
  40. .reduce((acc,val) => {
  41. if(!val || !acc[val]) return acc
  42. return acc[val]
  43. }, object)
  44.  
  45. const getName = west => getPropValue(west, "west.name")
  46. const analogy = west => getPropValue(west, "west.analogy")
  47. const age = west => getPropValue(west, "west.age")
  48.  
  49. const composition = (selectors, transformation) => {
  50. return input => {
  51. const dep = selectors.reduce((acc,val) => {
  52. acc.push(val(input))
  53. return acc
  54. }, [])
  55.  
  56. return transformation(...dep)
  57. }
  58. }
  59.  
  60. const manchester = composition(
  61. [getName, analogy, age],
  62. (name, analgoy) => `${name} ${analgoy}`
  63. )(west)
  64.  
  65. console.log(manchester)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement