Commit 96b25e1c authored by MohammadAli Keshavarz's avatar MohammadAli Keshavarz

this key word

parent 9914d384
...@@ -18,7 +18,7 @@ var x=23 ...@@ -18,7 +18,7 @@ var x=23
///////////////////////////////////// /////////////////////////////////////
// Lecture: Scoping // Lecture: Scoping
/*
// First scoping example // First scoping example
var a = 'Hello!'; var a = 'Hello!';
first(); first();
...@@ -46,5 +46,36 @@ function third() { ...@@ -46,5 +46,36 @@ function third() {
//console.log(c); //console.log(c);
console.log(a+d); console.log(a+d);
} }
*/
/////////////////////////////////////
// Lecture: The this keyword
//console.log(this);
calculateAge(1985);
function calculateAge(year) {
console.log(2016 - year);
console.log(this);
}
var john = {
name: 'John',
yearOfBirth: 1990,
calculateAge: function() {
console.log(this);
console.log(2016 - this.yearOfBirth);
function innerFunction() {
console.log(this);
}
innerFunction();
}
}
john.calculateAge();
var mike = {
name: 'Mike',
yearOfBirth: 1984
};
mike.calculateAge = john.calculateAge;
mike.calculateAge();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment