Is there any difference between this and self when assigning curried functions inside an object in JavaScript? -
suppose have following code:
<html> <head> <title>test</title> </head> <body> <header><h1>test</h1></header> <script type="text/javascript"> function myfunction2wrapper(arg1) { return function() { console.log("state of arg1 in curried function is: " + arg1); } } function myobject() { var internalstate1 = "a"; function myfunction1() { console.log("state of internalstate1: " + internalstate1); } myfunction1(); this.myfunction2 = myfunction2wrapper(internalstate1); //self.myfunction2 = myfunction2wrapper(internalstate1); myfunction2(); //console.log(myfunction2); console.log("done!"); }; myobject(); </script> </body> </html>
note in particular lines:
this.myfunction2 = myfunction2wrapper(internalstate1); //self.myfunction2 = myfunction2wrapper(internalstate1);
my question is: is there difference between this
, self
when assigning curried functions inside object in javascript?
there no self
implicit context/parameter. self
used inside function refers window.self
equal window
, not this
.
note: on global scope functions, this
refers window
.
Comments
Post a Comment