)
}
}
)
(
}
{
)
)
(
)
(
(
{
}
)
(
)
}
)
)
{
(
(
)
)
}
)
(
}

Prevent Class Method From Being Overwritten

  1. class A {
  2.   method() {
  3.     console.log('original')
  4.   }
  5. }
  6. Object.freeze(A.prototype)
  7.  
  8. let a = new A()
  9. a.method = function() { console.log('overwritten') }
  10. a.method()
  11.  
  12. class B {
  13.   method() {
  14.     console.log('original')
  15.   }
  16. }
  17.  
  18. let b = new B()
  19. b.method = function() { console.log('overwritten') }
  20. b.method()
I’m surprised I never tried/needed this before.
snippet.zone ~ 2021-24 /// {s/z}