This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setMovie(movie) { | |
this.movie = movie; | |
} | |
var theater = { | |
loadProjector: setMovie.bind(theater), | |
}; | |
var television = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Movie(title, director) { | |
this.title = title; | |
this.director = director; | |
} | |
var independenceDay = new Movie("Independence Day", "Roland Emmerich"); | |
console.log(independenceDay.title); // "Independence Day" | |
console.log(independenceDay.director); // "Roland Emmerich" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setMovie(movie) { | |
this.movie = movie; | |
} | |
var theater = { | |
loadProjector: setMovie, | |
playMovie: function(movie, previewLength) { | |
this.loadProjector(movie); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// option 1 | |
var theater = { | |
playMovie: function(movie, previewLength) { | |
this.loadProjector(movie); | |
setTimeout(function() { | |
console.log("Now playing: " + this.movie); | |
}.bind(this), previewLength); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setMovie(movie) { | |
this.movie = movie; | |
} | |
var theater = { | |
loadProjector: setMovie, | |
playMovie: function(movie, previewLength) { | |
this.loadProjector(movie); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeRobot(name, job) { | |
return { | |
name: name, | |
job: job, | |
introduce: function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}, | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
this.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
} | |
var bender = new Robot("Bender", "bending"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Robot(name, job) { | |
this.name = name; | |
this.job = job; | |
} | |
Robot.prototype.introduce = function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}; | |
var bender = new Robot("Bender", "bending"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Robot = { | |
init: function(name, job) { | |
this.name = name; | |
this.job = job; | |
}, | |
introduce: function() { | |
console.log("Hi! I'm " + this.name + ". My job is " + this.job + "."); | |
}, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Function definition and invocation | |
function speak(string) { | |
console.log(string); | |
} | |
speak("Hello"); // logs "Hello" | |
// Store in a variable | |
var talk = speak; | |
talk("Hi"); // logs "Hi" |