我一直在玩Jaxer,雖然這個概念非常酷,但我無法弄清楚如何定義客戶端和服務器上都可用的對象。我找不到任何可以定義對象的例子。使用Jaxer時定義對象
我希望能夠定義一個對象,並指定哪些方法將在服務器上可用,哪些方法將在客戶端上可用,哪些將在客戶端上可用,但在服務器上執行(服務器-代理)。這可以在不使用三個單獨的<script
>具有不同runat
屬性的標籤的情況下完成嗎?我希望能夠在同一個js文件中定義我的所有方法,如果可能的話,在html中使用三個單獨的標記來定義我的對象是不現實的...
基本上我想能夠做到這一點的一個js文件:
function Person(name) {
this.name = name || 'default';
}
Person.runat = 'both';
Person.clientStaticMethod = function() {
log('client static method');
}
Person.clientStaticMethod.runat = 'client';
Person.serverStaticMethod = function() {
log('server static method');
}
Person.serverStaticMethod.runat = 'server';
Person.proxyStaticMethod = function() {
log('proxy static method');
}
Person.proxyStaticMethod.runat = 'server-proxy';
Person.prototype.clientMethod = function() {
log('client method');
};
Person.prototype.clientMethod.runat = 'client';
Person.prototype.serverMethod = function() {
log('server method');
};
Person.prototype.serverMethod.runat = 'server';
Person.prototype.proxyMethod = function() {
log('proxy method');
}
Person.prototype.proxyMethod.runat = 'server-proxy';
另外,假設我能做到這一點,我將如何包含到HTML頁面是否正確?