代码之家  ›  专栏  ›  技术社区  ›  pistacchio

客户端和服务器端JS的JavaScript OOP库(node.js)

  •  3
  • pistacchio  · 技术社区  · 14 年前

    是否有任何Javascript OOP库能够以更基于类的方式轻松地使用类、固有等,以避免原型OOP在客户端(浏览器)和服务器(在我的例子中是node.js,但通常使用Javascript核心功能,因此无论解释器如何都可以使用它)?

    谢谢。

    4 回复  |  直到 13 年前
        1
  •  3
  •   user113716    14 年前

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

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

    从下载页面:

    RightJS也可用作服务器端库。在这种情况下,它只包含本机javascript单元扩展、类、观察者、选项单元以及来自util模块的所有非dom实用程序函数。

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

        2
  •  2
  •   Gian Marco    14 年前
        3
  •  1
  •   alessioalex    13 年前

    我刚刚发布 https://github.com/alessioalex/Cls 3天前。它非常轻,在引擎盖下有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();
    
        4
  •  0
  •   n3rd    14 年前

    几天前,Dirk Ginader,雅虎的前端工程师!告诉我最新发布的 YUI3 与node.js完美结合。

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