Live data from Hacker News

Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

github.com

1–10 of 43 posts

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#3
Can someone recommend a simple and easy-to-approach tutorial into ES7 decorators? I have used decorators successfully in my previous Python projects, and I'm eager to start using them in JS. Unfortunately, I haven't yet come across a good guide till now.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#4
Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfill (indeed, I don't think anyone's some it yet) I've only seen then done with decorators within classes.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#5

Can someone recommend a simple and easy-to-approach tutorial into ES7 decorators? I have used decorators successfully in my previous Python projects, and I'm eager to start using them in JS. Unfortunately, I haven't yet come across a good guide till now.

Take a look at http://babeljs.io

You can enable experimental es7 features: https://babeljs.io/docs/usage/experimental/

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#6

Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfill (indeed, I don't think anyone's some it yet) I've only seen then done with decorators within classes.

No these aren't the same as proxies. ES7 has class decorators that can only be used on class methods.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#7
Correct me if I'm wrong, but the necessity for decorators seem to have risen from the ES6 class syntax.

If we were doing classes/functions the old imperative style, we could have simply wrapped the RHS in a standard function that does what the decorator does.

  Animal.prototype.speedup = typeCheckDecorator("number", "number", function(x) {
    this.speed += x;
    return this.speed;
  });
I get that the class syntax makes things easier for people coming from other languages. And maybe makes static analysis easier. But still not sure if it was really needed.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#9

Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfill (indeed, I don't think anyone's some it yet) I've only seen then done with decorators within classes.

es7 decorators can also be used on vanilla objects, not just classes.

Re: Show HN: ES7 Decorator library adds types checking, memoization, and more to JS

#10
post #6

Is something similar to this possible with ES6 proxies? It'd be nice to use a lot of these features outside classes, but since proxies are far harder to polyfill (indeed, I don't think anyone's some it yet) I've only seen then done with decorators within classes.

No these aren't the same as proxies. ES7 has class decorators that can only be used on class methods.

I know they're not the same, but I'd love to be able to use some of the thins I can use with decorators, but on plain objects.
Post reply on HN