开发者

Accessors/mutators

I'm trying to create an object like this:

var DadosUtente = true;
var DevolucaoModelo = {
get UtNome() { return (DadosUtente) ? $("#UT_Nome") : $("#Equipamento_Nome")}
};

If i change the DadosUtente the selector returned changes too.

This works properly in Ch开发者_开发百科rome, but when i've tested it with Internet Explorer i get an error because the browsers is excepting :

In the rest of code i'm accessing the selectors like DevolucaoModelo.UtNome.val();

Can someone help me?

By the way, i've search a lot in google and tried others solutions but without success in IE.


Why not try:

var DadosUtente = true;
var DevolucaoModelo = {
    getUtNome : function() { return (DadosUtente) ? $("#UT_Nome") : $("#Equipamento_Nome")}
};

Update

If you don't want to call a function then do it like this:

var DadosUtente = true;
var DevolucaoModelo = {
    UtNome : (DadosUtente) ? $("#UT_Nome") : $("#Equipamento_Nome")
};

Then call it like DevolucaoModelo.UtNome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜