O'Reilly logo

Node Cookbook Second Edition by David Mark Clements

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring with prototypical inheritance

The functional mock-up created in the previous recipe, Writing a functional module mock-up, can be useful for getting familiar with a concept and may be perfectly adequate for small, simple modules with narrow scope.

However, the prototype pattern (among others), often used in Node's core modules, is commonly used by module creators and is fundamental to native JavaScript methods and objects.

Prototypical inheritance is more memory efficient. Methods sitting on a prototype are not instantiated until called; instead of being recreated on each invocation, they're reused.

On the other hand, it can be slightly slower than our previous recipe's procedural style because the JavaScript engine has the added overhead ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required