lesson_2.js
743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* Created by vitaliy on 21.09.15.
* this и непрямой вызов методов
*/
//var person = {
// name:"Vitaliy",
// age: 25,
// gender: "male",
// sayHi: function(){
// return "Hello!! My name is "+this.name;
// }
//};
//
//console.log(person.sayHi());
var sayHi = function(greet){
return greet+ "Hello!! My name is "+this.name;
};
var person = {
name:"Vitaliy",
age: 25,
gender: "male",
sayHi: sayHi
};
var anotherPerson = {
name:"Dima",
age: 25,
gender: "male",
sayHi: sayHi
};
console.log(person.sayHi("Hi"));
console.log(anotherPerson.sayHi("Hi"));
console.log(sayHi.call(person,"Hi"));
var bound = sayHi.bind(person);
console.log(bound("Hello there!"));