【问题标题】:Javascript OOP library for client and server-side js (node.js)用于客户端和服务器端 js (node.js) 的 Javascript OOP 库
【发布时间】:2011-04-25 01:25:34
【问题描述】:

是否有任何 Javascript OOP 库可以以更基于类的方式轻松处理类、继承等,以避免在客户端(浏览器)和服务器(在我的情况下为 Node)上与 JS 一起使用的原型 OOP .js,但一般都是用javascript核心函数,所以不管解释器都可以用)?

谢谢。

【问题讨论】:

    标签: javascript oop node.js


    【解决方案1】:

    我在 3 天前刚刚发布了https://github.com/alessioalex/Cls。它非常轻量级,具有 3 个底层函数(一个用于复制属性的 mixin 函数、一个用于继承的扩展函数和一个解析参数并使用前两个函数的 Cls 函数)。

    这适用于 Node.js 和浏览器,我已尽力记录和测试它。

    语法示例:

    var Person = Cls({
      methods: {
        constructor: function(name, age) {
          this.name = name;
          this.age = age;
        },
        present: function(otherDude) {
          return "Hello " + otherDude + " I'm " + this.name + ", my age is: " + this.age;
        }
      },
    });
    
    var Student = Cls({
      // extends the Person class
      uber: Person,
      present: function() {
        /**
         * call super function
         * note that this approach works even async (unlike other class libs)
         */
        return this.inherited('present', arguments);
      }
    });
    
    /**
     * since the constructor is missing
     * it will call the super constructor automatically
     */
    var alex = new Student('Alex', 25);
    alex.present();
    

    【讨论】:

      【解决方案2】:

      【讨论】:

        【解决方案3】:

        几天前,雅虎前端工程师 Dirk Ginader 告诉我,YUI3 的最新版本与 node.js 完美配合。

        我还没有证实我自己(不是 YUI 的忠实粉丝),但 Dirk 在 Yahoo! 工作下一个版本将(部分)基于 node.js 的邮件应用程序。这足以让我相信他知道他在说什么:-)

        【讨论】:

          【解决方案4】:

          The Rightjs 库有一个服务器版本 you can download

          我认为它特别考虑了 Node.js。

          来自下载页面:

          RightJS 也可用作服务器端库。在这种情况下,它只包含原生 JavaScript 单元扩展和 Class、Observer、Options 单元以及来自 Util 模块的所有非 DOM 实用程序函数。

          我们的服务器端构建遵循 CommonJS 原则,可以与 node.js 框架一起使用。

          【讨论】:

            猜你喜欢
            • 2012-01-06
            • 2015-10-21
            • 1970-01-01
            • 2012-05-29
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多