lesson_2.js 743 Bytes
/**
 * 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!"));