Learning Javascript: "this" keyword vs "arguments" object -


novice here, trying grasp how this , arguments differ , in circumstances 1 used instead of other?

for example, prototype function use this perform manipulation:

myobj.prototype.myfunc = function(){   return this.(some manipulation);   }    

similarly, arguments used loop through each argument manipulated:

function myfunc() {   (var = 0, < arguments.length; i++){     return arguments[i].(some manipulation)   } }  

basically in these 2 examples, 2 seem interchangeable, in terms of being accessed parameter further manipulation? i've been reading through various explanations here @ stack overflow of each alone (like this), in practice, i'm still quite confused use when comes application/context. when searches on search engines, "this" misunderstood or ignored, because of frequency of appearance...

any appreciated!

this object on function invoked. example, if called function myobj.foo(), within scope of foo, this refer myobj. value of this can tricky. example, did this:

var foofn = myobj.foo; foofn(); 

in case, this wouldn't refer myobj, rather global window object.

that's this in nutshell.

as arguments, array-like object (not true array) of arguments passed function. suppose have function function myfn(foo, bar). can pass more 2 arguments myfn. if called myfn(1, 2, 3), how access third argument? that's arguments for. in case, arguments have 3 elements: 1 (corresponding foo parameter), 2 (corresponding bar parameter), , 3 (the parameter).

you can make use of arguments object support overloaded versions of functions.


Comments