view source/examples/call-apply.js @ 162:77e87f1b5811 core-javascript

$ hg merge core-javascript.closure-exercises # done, at least for now
author jf3243
date Wed, 09 Nov 2011 17:00:38 +0000
parents 48305b89a155
children
line wrap: on
line source

// Things related to call and apply that JS programmers should know.


// Standard names for native code functions.

var array_slice = Array.prototype.slice;
var function_call = Function.prototype.call;
var function_apply = Function.prototype.apply;

var arguments_to_array = function(args){

  return array_slice.call(args);
};


(function()
{
    var args = (function(){return arguments;})(0,1,2,3);
    '' + args === '[object Object]' || ddt();
    '' + arguments_to_array(args) === '0,1,2,3' || ddt();
})();


var return_this = function(){return this;};
var global = return_this();

var isthisable = function(obj){

  return return_this(obj) === global;
};