Last active
January 4, 2016 04:18
-
-
Save Chryus/8567220 to your computer and use it in GitHub Desktop.
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 yao = { | |
self: function () { return this } | |
} | |
console.log(yao === yao.self()); | |
//yao.self is equal to yao, so this return a boolean value of true. | |
> var lebron = { | |
... occupation: "basketball", | |
... introduction: function () { | |
..... return "My name is LeBron and I play " + this.occupation | |
..... } | |
... } | |
undefined | |
> lebron.introduction(); | |
'My name is LeBron and I play basketball' | |
//we can call this.occupation or lebron.occupation because lebron is the object | |
> var lebron = { | |
... occupation: "basketball", | |
... introduction: function () { | |
..... return "My name is LeBron and I play " + lebron.occupation | |
..... } | |
... } | |
undefined | |
> lebron.introduction(); | |
'My name is LeBron and I play basketball' | |
var square = { | |
side_length: 4, | |
area: function () { | |
return this.side_length * this.side_length; | |
} | |
} | |
console.log(square.area()); | |
//this refers to the square object anywhere inside the object. Note that this is a standalone object. | |
var me = { | |
first_name: "Matthew", | |
last_name: "Powers", | |
full_name: function () { | |
return this.first_name + " " + this.last_name; | |
} | |
} | |
console.log(me.full_name()); | |
//again, this refers to the object. | |
circle.circumference = Math.PI * (circle.radius * circle.radius); | |
314.1592653589793 | |
//set the standalone circle object's circumference method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment