本文介绍了(开源)JavaScript Prototypical OO的例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bounty编辑:

我正在寻找用原型OO范例编写的代码(想想自)。不是原型OO和经典OO的混合物。我不希望看到通用的OO包装器,而只是使用原型OO技术和原型OO技术。

I'm looking for code written in a pure prototypical OO paradigm (think Self). Not a mixture of prototypical OO and classical OO. I don't want to see generic OO wrappers but simply usage of prototypical OO techniques and only prototypical OO techniques.

参考相关问题:

在上面的问题中,我主要关注

In the above question I mainly focused on

我们是否需要构造函数和初始化逻辑,有哪些替代方案?

Do we need constructors and initialization logic, What are the alternatives?

新问题:

基本上有任何 javascript原型的好例子 OO在大型开源项目中?

Basically are there any good examples of javascript prototypical OO in large open source projects?

澄清:

我必须澄清我的意思是原型OO

I will have to clarify what I mean with prototypical OO :


  • 没有类。只有对象。

  • 对类的概念进行仿真,再次只有对象和克隆对象可以创建新对象。

  • There are no classes. There are only Objects.
  • There is zero emulation of the concepts of classes, again there is only objects and cloning objects to create new objects.

进一步澄清原型OO:

JavaScript中的原型OO与经典OO仿真之间的区别是非常灰色的区域。这不是我避免使用经典的OO。我想以学术的方式学习原型OO,而不学习经典OO仿真和原型OO的(可能更优化)组合。

The difference between prototypical OO in JavaScript and classical OO emulation is a very grey area. It's not that I value avoiding classical OO. I want to learn prototypical OO in an academic fashion in it's own right, without learning the (probably more optimum) combination of classical OO emulation and prototypical OO.

这就是为什么我禁止课程,只是为了让我能够以纯粹的方式看到这些技术并扩展我自己的OO工具包。

This is why I "ban" classes, just so that I can see these techniques in a pure fashion and extend my own OO tool kit.

示例:

像jQuery这样的热门示例无法达到第二个标准。 jQuery 对象是一个大类仿真。它侧重于从类创建新对象,而不是克隆现有对象。

Popular examples like jQuery fail to meet the second criteria. The jQuery object is one big class emulation. It focuses on creating new objects from a class rather then cloning existing objects.

如果我真的知道使用pure原型OO的任何例子,我会告诉你。我相信99%的JavaScript OO受到经典仿真的影响太大。

If I actually knew any example of using "pure" prototypical OO I would have shown you. I believe 99% of JavaScript OO is too heavily influenced by classical emulation.

奖励积分

如果


  • 它的编号很好/有文件记录

  • 有单元测试

  • 在github上。

我还接受有关如何编写原型OO代码的文章/教程和示例这超出了你琐碎的hello world应用程序。

I will also accept articles / tutorials and examples on how to write prototypical OO code that goes beyond your trivial hello world application.

推荐答案

你找不到它。

前段时间我去寻找这种事情,这就是我发现的:(查看。)本文讨论了 Self 的最佳实践,原始语言,以及最佳实践是使用traits object idiom,这是让您的对象继承自仅包含方法的traits对象,而不是对象特定的数据。换句话说,一个可疑的类似于对象。

I went looking for this sort of thing a while ago, and this is what I found: the Self Paper Organizing Programs Without Classes (Look at Citeseer for a PDF version.) This paper discusses the best practices for Self, the original prototypal language, and the best practice is to use the "traits object idiom", which is to have your objects inherit from "traits objects" that contain only methods, and no object specific data. In other words, an object that is suspiciously like a class.

即使是原始的原型语言也会模拟类。

Even the original prototypal language emulates classes.

这篇关于(开源)JavaScript Prototypical OO的例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 17:23