let x = (...args) => { /* some function gunk */ };
So I wonder if this is allowed: let x = ...args => args.join(',')21–30 of 48 posts
let x = (...args) => { /* some function gunk */ };
So I wonder if this is allowed: let x = ...args => args.join(',')Sometimes I wonder if a lot of the anti-coffeescript people in this forum are simply Javascript native programmers and don't want any change period. I can't think of many programming languages that stop changing - seems to be the norm.
Knowing the value of `this` at the beginning of a function makes for much more readable code. Fat arrow and all the other ES6 features available in CoffeeScript and Traceur are now too valuable to live without imho.
I am not pleased at seeing language bloat. Look at what happened with C++11. Languages are supposed to give a common base for developers to read and write the same code. New developers should be able to get up to speed quickly, and see the intent of the other developers, which is one of the reasons Linux is written in C instead of C++. "Look at all that saved typing!" Yeah, shockingly there were only a few characters…
Wouldn't it be: let x = (...args) => { /* some function gunk */ }; So I wonder if this is allowed: let x = ...args => args.join(',')
you can't use spread arguments without the ().
This article is written for someone who already understands the old issue that this is fixing (there's nothing wrong with writing it like that). But for someone like me that doesn't understand when you need to use this `bind()` stuff and the context your function is in (if I'm even saying that correctly), what can I read to get a better understanding of what's going on here? In other words, what do I need to read bef…
var myObj = {
foo: 'bar',
baz: function() {
console.log(this.foo); //would give you 'bar', as expected
//but if you have some code that changes the meaning of this, for example:
$('.button').click(function() {
console.log(this.foo); //undefined, since now "this" refers to the scope of the event's callback function
});
//but if you use bind:
$('.button').click((function() {
//now "this" is scoped to refer to the main object
console.log(this.foo); //gives you 'bar'
}).bind(this));
}
}> If you’re a JavaScript programmer, chances are you’ve seen (and done) something like this before:
var listener = node.addEventListener("click", function(event) {
let _target = event.target;
this.handleClick(_target);
}.bind(this));
I had to go look up `let` in JavaScript[1]. It appears to still be a bleeding-edge feature not widely supported[2] outside of Firefox... not even in Node with the --harmony flag. I wonder if this is meant to be subtle pro-ES6 propaganda, or the author really takes `let` for granted and doesn't realize most JS programmers have never seen it :)1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
I am not pleased at seeing language bloat. Look at what happened with C++11. Languages are supposed to give a common base for developers to read and write the same code. New developers should be able to get up to speed quickly, and see the intent of the other developers, which is one of the reasons Linux is written in C instead of C++. "Look at all that saved typing!" Yeah, shockingly there were only a few characters…
asyncOperation(_.bind(function(x) { this.x += x; }, this));
or... asyncOperation(goog.bind(function(x) { this.x += x; }, this));
or... asyncOperation(function(x) { this.x += x; }.bind(this));
or... asyncOperation($.proxy(function(x) { this.x += x; }, this));
or even... var self = this;
asyncOperation(function(x) { self.x += x; });
...then I'd have a lot of nickels. Binding a function to the current scope is _insanely_ common - adding syntax specifically for it makes sense. I would argue that it reduces the cognitive overhead of the language, since rather than needing to read another method call, examine arguments, etc. I can simply translate a 2-character symbol into the meaning "outer-context-bound function". There's a lot more bloat in the above examples than there is in this: asyncOperation((x) => { this.x += x; });
This is like arguing that the '+' operator bloats the language, when we could all just be using Number(17).plus(Number(43));Did anyone else do a double take reading this? > If you’re a JavaScript programmer, chances are you’ve seen (and done) something like this before: var listener = node.addEventListener("click", function(event) { let _target = event.target; this.handleClick(_target); }.bind(this)); I had to go look up `let` in JavaScript[1]. It appears to still be a bleeding-edge feature not widely supported[2] outside of Firefox... no…