I don't quite understand the difference between the following two lines of code. In my code, the line with "apply" works the way I want it to, and the line with just regular push doesn't.   So what is really going on when both of thes...
I'm learning JavaScript and I'm currently trying to figure out why (in Spidermonkey)  [].concat.apply([1], [[2]])   returns the expected [1, 2], but  Array.concat.apply([1], [[2]])   returns [2] instead of [1, 2].  Could someone provide a goo...
In JavaScript, I can use apply to pass an array as arguments to a function:  var f = function (n,m) {},     args = [1,2];  f.apply(null, args);   I now need to do something similar in PHP i.e. pass an array of items as 'separate' arguments to...
I wanted to invoke a function using the javascript apply() method. This works fine if the function has no arguments. i.e.  function test() {   console.log(this); }  body = document.getElementsByTagName("body")[0]; // shortcut to body element...
It's frustrating to have to manually set the scope of an object every time I declare a callback in JavaScript, but it's a fact of life. I wondered if I could do it by passing [mycallback].apply as the callback, and the scope object as an argu...
I'm writing a global error handling "module" for one of my applications.  One of the features I want to have is to be able to easily wrap a function with a try{} catch{} block, so that all calls to that function will automatically have th...
In the CoffeeScript docs for array splicing, what is the purpose of the trailing , _ref?  CoffeeScript:  numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] numbers[3..6] = [-3, -4, -5, -6]   Compiles to:  var numbers, _ref; numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8...
Anyone knows why in javascript this works  m = Math.max m.apply(null, [1,2,3])   but this doesn't?  m = Math.max.apply m(null, [1,2,3])   It throws the exception:     TypeError: Function.prototype.apply was called on undefined, which is a undefin...
I'm not asking how to use it. I know how to use it.  But when apply invokes the function that called it, how exactly does it pass an array of arguments into a function that was not written to take an array for an argument? Does it combine its giv...

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.