2010-10-13 144 views
3

是否有任何Javascript OOP庫能夠以更基於類的方式輕鬆地與類,內置類等一起工作以避免與JS一起工作的原型OOP在客戶端(瀏覽器)和服務器上(在我的情況下Node.js,但通常使用JavaScript核心函數,這樣就可以使用,無論解釋器)?用於客戶端和服務器端js(node.js)的Javascript OOP庫

謝謝。

回答

3

The Rightjs庫的服務器版本爲you can download

我認爲它具有特定的Node.js。

從下載頁面:

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

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

0

幾天前,雅虎前端工程師Dirk Ginader告訴我,最新發布的YUI3完美地與node.js一起使用。

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

1

我剛剛發佈https://github.com/alessioalex/Cls 4天前。它非常輕量級,有3個函數(混合函數用於複製屬性,擴展函數用於繼承以及用於解析參數並使用前兩個函數的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(); 
相關問題