voorhoede / riotjs-style-guide

Opinionated RiotJS Style Guide for teams.
Creative Commons Zero v1.0 Universal
287 stars 22 forks source link

DRY code instead of redeclaring "magic es6 methods" #51

Closed MartinMuzatko closed 8 years ago

MartinMuzatko commented 8 years ago

I agree that the so called magic es6 methods add() {} was confusing first, but it is riot-specific and usually

But I'd avoid writing up the additional tag.add = add and rather use the original syntax or write this.add = function() {}.bind(this)instead of this:

tag.add = add;

function add() {
    if (tag.text) {
        tag.todos.push({ title: tag.text });
        tag.text = tag.input.value = '';
    }
}

Discussion?

jbmoelker commented 8 years ago

@MartinMuzatko add() {} is non-standard. Both tag.add = add; and this.add = function() {}.bind(this) are both at least valid JavaScript.

I think the rest comes down to preference. We have a preference to "put tag properties and methods on top", which is in turn based on Angular Style Guide > "Bindable members on top". In short it ensures you get a "table of contents of a tag's properties and methods" and that's why it works well for us.

MartinMuzatko commented 8 years ago

Thanks for explaining. I have to admit it is confusing when mixing event handlers and "private" methods