Live data from Hacker News

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

github.com

11–20 of 43 posts

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

#11
post #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…

Static analysis is one of the end goals of this project; the other is generating documentation.

Decorators are definitely NOT needed for achieving the current functionality.

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

#12

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.

Really? Any tutorials/posts/examples of using them on plain objects anywhere?

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

#13

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.

you dont need proxies, here is how decorators work and how you can implement them yourself, without the syntactic sugar obviously

https://github.com/wycats/javascript-decorators

Proxies are an entire different thing.

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

#14
post #6

Earlier quoted context omitted.

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.

You can also use them on class declarations themselves and object literals - https://github.com/wycats/javascript-decorators#object-liter...

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

#16

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.

I once implemented type checking in ES5 as a proof-of-concept: https://github.com/panuhorsmalahti/typed-javascript

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

#17
post #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…

[deleted]

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

#19

Earlier quoted context omitted.

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

Really? Any tutorials/posts/examples of using them on plain objects anywhere?

Yeah, check some of the examples in the readme
Post reply on HN