×
this
in the following example:var data = this; console.log(data);
function logThis(){ return this; } logThis(); // ?
var instructor = { firstName: 'Tim', sayHi: function(){ console.log("Hello! " + this.firstName); } } instructor.sayHi() // ?
var instructor = { firstName: 'Tim', info: { catOwner: true, boatOwner: true }, displayInfo: function(){ console.log("Cat owner? " + this.catOwner); } } instructor.displayInfo() // ?
var instructor = { firstName: 'Tim', info: { catOwner: true, boatOwner: true, displayLocation: function(){ return this.data.location; }, data: { location: "Oakland" } }, } instructor.info.displayLocation() // ?
var instructor = { firstName: 'Tim', info: { catOwner: true, boatOwner: true, displayLocation: function(){ return this.location; }, data: { location: "Oakland", logLocation: this.displayLocation } }, } instructor.info.data.logLocation() // Why might we be getting an error here?
Complete the following exercises here
When you're ready, move on to Introduction to Object Oriented Programming in JavaScript