Javascript/Jquery 3.3从非严格调用到严格调用和顺序调用的转换函数
我正在尝试将一个旧的非严格函数转换为一个与严格版本和jQuery3.3兼容的版本 旧函数允许我依次调用各种函数,得到一个单一的最终结果,而在新函数中,经过多次尝试后,我无法重现这些结果 旧功能是:Javascript/Jquery 3.3从非严格调用到严格调用和顺序调用的转换函数,javascript,jquery,sequential,strict,Javascript,Jquery,Sequential,Strict,我正在尝试将一个旧的非严格函数转换为一个与严格版本和jQuery3.3兼容的版本 旧函数允许我依次调用各种函数,得到一个单一的最终结果,而在新函数中,经过多次尝试后,我无法重现这些结果 旧功能是: var num_modali = 0; _modale = function(){ this.livello_m = num_modali; this.percorso = function(){ r
var num_modali = 0;
_modale = function(){
this.livello_m = num_modali;
this.percorso = function(){
return (this.livello_m > 0) ? $('body').find('#modale_' + this.livello_m).find(modale_content) : $('body');
};
this.listarecord = function(){
return lista_record = (this.livello_m > 0) ? '#lista_records_modale' : '#lista_records';
};
this._pre = function(){
this.livello_m--;
return this;
};
this._go = function(){
return this.percorso();
};
this._getlivello = function(){
var livello = (this.livello_m > 0) ? this.livello_m : 0;
return livello;
};
this._chiudi = function(where){
$destroy_modale();
return this;
};
this._delete = function(what){
this.percorso().find(this.listarecord()).find(what).remove(what);
return this;
};
if(this instanceof _modale){
return this;
}else{
return new _modale();
}
};
有了这个,我也可以这样调用:\u modale()。\u pre()。\u pre()。\u go()代码>
全局变量num_modali
由第二个函数使用,该函数处理模式变量的管理
新功能:
var _modale = {
livello_m: num_modali,
percorso: function(){
return (this.livello_m > 0) ? 'body #modale_' + this.livello_m + ' .modale_content' : 'body';
},
listaRecord: function(){
return (num_modali > 0) ? '#lista_records_modale' : '#lista_records';
},
pre: function(){
return this.livello_m - 1;
},
go: function(){
return this.percorso();
},
getlivello: function(){
return (this.livello_m > 0) ? this.livello_m : 0;
},
chiudi: function(){
modale.destroyModale();
//return this;
},
_delete: function(what){
_modale.percorso().find(_modale.listaRecord()).find(what).remove(what);
}
};
如果我尝试执行相同的顺序调用:\u modale.pre().pre().go()代码>
return\u modale.pre(…).pre不是函数
如何根据严格的指令更改函数并获得相同的操作?您需要在函数中返回此
,以使其可链接:
pre: function(){
this.livello_m--;
return this; // Here
}
您需要在函数中返回此
,以使其可链接:
pre: function(){
this.livello_m--;
return this; // Here
}
所有想要链接的函数都需要返回\u modale
的实例。(这与strict或jQuery无关)所有想要链接的函数都需要返回\u modale
的实例。(这与strict或jQuery无关)完美,非常感谢,我已经尝试过,但显然我做了错事完美,非常感谢,我已经尝试过,但显然我做了错事