![](/img/trans.png)
[英]Get node.js server-side object available in client-side javascript code
[英]Javascript OOP library for client and server-side js (node.js)
是否有任何Javascript OOP庫可以輕松地使用類,內在等更基於類的方式來避免在客戶端(瀏覽器)和服務器上使用JS的原型OOP(在我的情況下Node.js,但一般來說使用javascript核心函數,這樣無論翻譯都可以使用)?
謝謝。
我剛剛發布了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.