function myObject() { this.property1 = "value1"; this.property2 = "value2"; var newValue = this.property1; this.performMethod = function() { myMethodValue = newValue; return myMethodValue; }; } var myObjectInstance = new myObject(); alert(myObjectInstance.performMethod());
var user = { name: "Rahul Mhatre", whatIsYourName: function() { console.log(this.name); }};user.whatIsYourName(); // Output: "Rahul Mhatre",var user2 = { name: "Neha Sampat"};user.whatIsYourName.call(user2); // Output: "Neha Sampat"