Skip to Content
JavaScript : Object-Oriented Programming
book

JavaScript : Object-Oriented Programming

by Kumar Chetan Sharma et al
August 2016
Beginner to intermediate
847 pages
17h 28m
English
Packt Publishing
Content preview from JavaScript : Object-Oriented Programming

Borrowing a constructor

One more way of implementing inheritance (the last one in the chapter, I promise) has to do again with constructor functions, and not the objects directly. In this pattern the constructor of the child calls the constructor of the parent using either call() or apply() methods. This can be called stealing a constructor, or inheritance by borrowing a constructor if you want to be more subtle about it.

call() and apply() were discussed in Chapter 4, Objects but here's a refresher: they allow you to call a function and pass an object that the function should bind to its this value. So for inheritance purposes, the child constructor calls the parent's constructor and binds the child's newly-created this object as the parent's ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

JavaScript: Functional Programming for JavaScript Developers

JavaScript: Functional Programming for JavaScript Developers

Ved Antani, Simon Timms, Dan Mantyla
Mastering JavaScript Object-Oriented Programming

Mastering JavaScript Object-Oriented Programming

Andrea Chiarelli, Lyubomyr Rudko

Publisher Resources

ISBN: 9781787123595Supplemental Content