this - JavaScript: unexpected typeof result -
this - JavaScript: unexpected typeof result -
i have array iterator function:
function applycall(arr, fn) { fn.call(arr[0], 0, arr[0]); } and code
var arr1 = ['blah']; applycall(arr1, function (i, val) { alert(typeof this); // object why?? alert(typeof val); // string alert(typeof(this === val)) // alerts false, expecting true }); why typeof this within inline function object instead of string?
jsfiddle here
when method called in javascript, internally sets this calling object: https://developer.mozilla.org/en-us/docs/javascript/reference/global_objects/function/apply
...and primitive values boxed.
by "boxed," mean primitive wrapped in object. note applies first argument apply/call. other arguments become function parameters not "boxed."
javascript this typeof
Comments
Post a Comment