According to me this is only being used if you need to call constructor like below
var dogObj = function(){
this.bark = "woof";
}
var dog1 = new dogObj();
console.log(dog1.bark);
Is there any cases where I use this on object literal?
var bark = {
this.bark = "dog"
}
Is above code valid? If yes,how do I call it?
var o={msg:'hello world',fn:function(){alert(this.msg)}};o.fn();oobject?bindis what you're looking for. It, in a sense, allows you to "edit" thethiscontext of a function and returns the new edited function without calling it. Thus when you're ready to call it, you can call it the normal way like you usually would with the new context bound to the function.