May 2018
Intermediate to advanced
492 pages
12h 3m
English
This sort of object class definition is new to JavaScript with ES-2015. It simplifies defining classes over previous methods and brings JavaScript class definitions closer to the syntax in other languages. Under the hood, JavaScript classes still use prototype-based inheritance, but with a simpler syntax, and the coder doesn't even have to think about the object prototype.
We can reliably determine whether an object is a note with the instanceof operator:
$ node> const Note = require('./Note');> typeof Note'function'> const aNote = new Note('foo', 'The Rain In Spain', 'Falls mainly on the plain');> var notNote = {}> notNote instanceof Notefalse> aNote instanceof Notetrue> typeof aNote'object'
This shows ...
Read now
Unlock full access