簡體   English   中英

客戶端和服務器端js的Javascript OOP庫(node.js)

[英]Javascript OOP library for client and server-side js (node.js)

是否有任何Javascript OOP庫可以輕松地使用類,內在等更基於類的方式來避免在客戶端(瀏覽器)和服務器上使用JS的原型OOP(在我的情況下Node.js,但一般來說使用javascript核心函數,這樣無論翻譯都可以使用)?

謝謝。

Rightjs庫有一個可以下載的服務器版本。

我認為它特別考慮到Node.js。

從下載頁面:

RightJS也可用作服務器端庫。 在這種情況下,它只包含本機JavaScript單元擴展和Class,Observer,Options單元以及Util模塊中的所有非DOM實用程序功能。

我們的服務器端構建遵循CommonJS原則,可以與node.js框架一起使用。

我剛剛發布了https://github.com/alessioalex/Cls 3天前。 它非常輕量級,底層有3個函數(一個用於復制屬性的mixin函數,一個用於繼承的extends函數和用於解析參數並使用前兩個函數的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();

幾天前,Yahoo!的前端工程師Dirk Ginader告訴我,最新版本的YUI3與node.js完美配合。

我沒有證實我自己(不是YUI的忠實粉絲)但Dirk正在雅虎工作! 郵件應用程序,其下一個版本將(部分)基於node.js. 這足以讓我相信他知道他在說什么:-)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM