4 ms·
I'm 'ardkore and rigidly enforce `var functionName = function functionName() {}`, under threat of flaying.
by grumblestumble 12y ago
I'm 'ardkore and rigidly enforce `var functionName = function functionName() {}`, under threat of flaying.
- grumblestumble 12y agoSeriously though, when binding functions to object properties, the seemingly redundant syntax is worth the cleaner call stack: `this.functionName = function functionName() {}`. Simply named functions in promises can also be helpful : `promiseFn().then(function success() {}, function failure() {}` vs. the more common anonymous inline functions.
- thedufer 12y agoWhat's the goal there? v8, at least, will give the name in a stack trace even if the function is declared like `var a = function(){}`.
- Cthulhu_ 12y agoReally? I'm using Chrome, and at least for me, unfortunately it doesn't. Second, V8 isn't the only JS engine out there, a lot of tools will simply put the function as 'anonymous function' in stack traces.
- thedufer 12y ago> var a = function(){throw Error('err')} undefined > try{a()}catch(err){err.stack} "Error: err at Error (native) at a (<anonymous>:2:26) at <anonymous>:2:5 at Object.InjectedScript._evaluateOn (<anonymous>:641:39) at Object.InjectedScript._evaluateAndWrap (<anonymous>:580:52) at Object.InjectedScript.evaluate (<anonymous>:495:21)" The "at a" is what we're looking for. I develop largely in Chrome; its been doing this for months, at least. It also works in IE11 (the only version I have readily available), Firefox, and Safari.