Seiten

JavaScript Reuse by Inheritance

After having studied some JavaScript books I discovered some useful parts of the JavaScript language that best suited to me. One of my good parts is concerning patterns for reuse by inheritance:

Avoid class like inheritance using the new function. Especially for Java developers this approach might cause confusion and is error prone because inheritance using prototypes does not always behaves like some class minded developer might think (e.g. overloading of properties, prototype vs. local properties/methods). As inheritance is mainly used for the reuse of application logic, JavaScript offers other concepts for reuse that fit better with the dynamic aspect of the language:

  • Copying of properties/methods,
  • Mix-Ins or 
  • Borrowing Methods
(as mentioned in JavaScript Patterns by Stefanov).

Keine Kommentare:

Kommentar posten