Why a member of a function call cannot be assigned to a variable

I am working on a transcoder for a project and have come across an unusual edge case.

I have the following:

function a(func){
    return func.call()
}

for various reasons, the transcoder wants to change it to:

function a(func){
   var tmp = func.call;
   var res = tmp()
   return res;
}

However, the call tmp()returns with tmp is not a function. If I debug and pause only this line, it tmpis defined as a function.

Is this due to the fact that the signature function call(){ [native code]}?

Are there any other functions that will cause such errors?

Is there any way around this other than just not doing it?

EDIT: I found another case, it looks like this might be due to the context of the object:

a = { toString: null }.propertyIsEnumerable
a("toString")

produces the same error.

EDIT: ; , , . , . , func.call() , , .

+4
1

,

 var f = obj.mymethod;
 f();

 var f = obj.mymethod.bind(obj);
 f();
+5

All Articles