Created
August 18, 2014 17:15
-
-
Save Hollyw00d/2f440879e51913bed740 to your computer and use it in GitHub Desktop.
Object Scope Help and [return] Keyword Definition Needed
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
// From "Passing Objects into Functions" > 28/33 > Objects I > CodeAcademy.com | |
// QUESTIONS: | |
// 1. Per line 17, I understand that the I am passing the [ageDifference] object's properties as parameters into the [Person] constructor. Does an object always have access to an object constructor's properties when the [this] keyword is used, along with the object using the same properties as the object constructor? | |
// 2. Per line 17, what does the [return] keyword do? When should the [return] be used? | |
function Person (name, age) { | |
this.name = name; | |
this.age = age; | |
} | |
// We can make a function which takes persons as arguments | |
// This one computes the difference in ages between two people | |
var ageDifference = function(person1, person2) { | |
return person1.age - person2.age; | |
} | |
var alice = new Person("Alice", 30); | |
var billy = new Person("Billy", 25); | |
// get the difference in age between alice and billy using our function | |
var diff = ageDifference(alice, billy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment