TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Classes for javascript that you'd actually use

52 点作者 jayferd超过 13 年前

9 条评论

jarek-foksa超过 13 年前
Please, please read <a href="http://killdream.github.com/blog/2011/10/understanding-javascript-oop/" rel="nofollow">http://killdream.github.com/blog/2011/10/understanding-javas...</a><p>Prototypical inheritance as of ES5 is really not that hard. Here is the same example rewritten with prototypes: <a href="https://gist.github.com/1558929" rel="nofollow">https://gist.github.com/1558929</a>
评论 #3425264 未加载
评论 #3423754 未加载
评论 #3423729 未加载
mathrawka超过 13 年前
It seems that everyone wants to add classes to Javascript. I understand that prototype-based programming is a bit of a change from class-based programming, but this is starting to feel like wasted energy on a problem that does not need solving.<p>What benefits do developers get from using a 3rd-party library to create classes in a prototype-based OOP language? Why can't developers just learn that there is more than one style of OOP, and go with the flow?
评论 #3423057 未加载
ricardobeat超过 13 年前
Pretty nice. Ends up being similar in structure to classes in coffeescript.<p>The very last lines worry me a bit though:<p><pre><code> // instantiate objects by calling the class MyClass() // =&#62; init! // allocate blank objects with `new` new MyClass // nothing logged </code></pre> Having `MyClass()` and `new MyClass` behave differently is totally unwarranted and will cause lots of confusion.
评论 #3425258 未加载
bmuon超过 13 年前
Pjs may work for a small number of objects, but if you're dealing with a large number of intances from a single class Pjs is going to use much more memory than needed. That's because the recommended method P(function () { this.method = fn; }) is declaring all methods as instances properties instead of using the prototype, so all methods are actually new functions in new own properties instead of properties of a shared object (the prototype).
评论 #3425239 未加载
ale55andro超过 13 年前
normally all you'd need is a 2 liner utility method to facilitate inheritance. For the rest you can use js as it is with it's actual language features which maybe a little verbose (my only lament so far) and prototypical based but you will begin to appreciate it in the long run. I don't like the exaggerated syntactic sugar that many libs bring in, that try to abstract and tuck away js as it is, making it pretend to be a class based language when it is not. That said, this particular lib's size and the direct problems it tries to solves are done so elegantly. It's hard to ignore the good job the author has done!
kibibyte超过 13 年前
What are the differences between this and something like MooTools? What benefits does P.js offer?<p>(Note: I was only introduced to MooTools today, so I have limited knowledge about it.)
评论 #3423280 未加载
limeblack超过 13 年前
pjs certainly deserves props for being creative with the function passing, and variable context. I haven't seen that exact usage before.<p>It seems every couple weeks javascript class library named X is released, avoiding issue Y, and implementing fuctionality Z.<p>Using `prototype` isn't terribly far off from the class systems people keep creating, so I can pretty much assume a single class library is going to reach deep adoption anytime soon.
leeoniya超过 13 年前
been using this one recently: <a href="https://github.com/ded/klass" rel="nofollow">https://github.com/ded/klass</a>
aurynn超过 13 年前
I'd use this. Does it work with node.js?
评论 #3423033 未加载