Skip to content

Instantly share code, notes, and snippets.

@joseanpg
Created September 20, 2012 20:13
Show Gist options
  • Save joseanpg/3758072 to your computer and use it in GitHub Desktop.
Save joseanpg/3758072 to your computer and use it in GitHub Desktop.
Function.prototype.call.call behaviour

Function.prototype.call.call(function(x){alert(x);},1) // why undefined?

@garethheyes [question] (https://twitter.com/garethheyes/status/248797836307734528)

Answer

let call = Function.prototype.call

f.call(alpha,arg) ->
       f[[Call]](alpha,arg) -> 
       Execute f[[Code]] with *ThisValue* = alpha and *arguments* = [arg] 

f.call.call(f,arg) -> 
       call[[Call]](f,arg) -> 
       Execute call[[Code]] with *ThisValue* = f and *arguments* = [arg] ->
       f[[Call]](arg) ->
       Execute f[[Code]] with *ThisValue* = arg and *arguments* = [] ->
       *x* is undefined and *this* == arg


Function.prototype.call.call(function(x){alert(this+','+x);},1) // 1,undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment