17.11.2015 Views

JavaScript_Succinctly

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

var john = new Person(); // No argument is passed so fullName is not<br />

added to the instance.<br />

console.log(john.whatIsMyFullName()); // Logs 'John Doe'.<br />

<br />

The concept to take away here is that the keyword this is used to refer to instances<br />

when used inside of a method contained in the prototype object. If the instance does<br />

not contain the property, the prototype lookup begins.<br />

Notes<br />

If the instance or the object pointed to by this does not contain the property being<br />

referenced, the same rules that apply to any property lookup are applied, and the<br />

property will be "looked up" on the prototype chain. So in our example, if the fullName<br />

property was not contained within our instance, fullName would be looked for at<br />

Person.prototype.fullName, then Object.prototype.fullName.<br />

112

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!