構造函數function layer_custom() { this.json = { type: '', title: null, content: '', area: '', //skin:'layui-layer-rim', //offset: btnAlign: 'c', closeBtn: null, // shade: 0, shade: [.1, '#000'], shadeClose: false, time: 0, id: 'onlyOne',//這個id屬性不想被覆蓋 anim: 0, resize: false, yes: null, no: null, cancel: null, btn1: null, btn2: null, btn3: null }}實例方法// 最多可傳入3個自定義按鈕名稱layer_custom.prototype.alertCustBtn = function(id, title, Arrbtn, content, area, fn, fn1, fn2, suc, destory) { this.json.type = 1; this.json.id = id; this.json.btn = Arrbtn; //Arrbtn 是個數組 this.json.title = title; this.json.closeBtn = 1; this.json.content = content; this.json.area = area; this.json.btn1 = function(index, layero) { fn && fn(index); // layer.close(index); }; this.json.btn2 = function(index) { fn1 && fn1(index); // layer.close(index); }; this.json.btn3 = function(index) { fn2 && fn2(index); // layer.close(index); }; this.json.success = function() { suc && suc(); } this.json.end = function() { destory && destory(); } layer.open(this.json);};調用代碼 var did = 'dialog1'; //目前layer_custom上的id被覆蓋成dialog1了, //但是下次調用alertCustBtn時構造函數上的值就變成dialog1了,能不能讓構造函數不記錄最近一次的傳值,而是在每次調用實例方法,我不覆蓋屬性,就用構造器上默認的屬性值呢? $layer.alertCustBtn(did, '案件詳情', ['返回'], '', ['840px', '600px'], (index) => { layer.close(index); }, null, null, () => { _tpl.layuiTplRender('caseDetailPanel_tpl', did, {}); });目前layer_custom上的id被覆蓋成dialog1了,但是下次調用alertCustBtn時構造函數上的值就變成dialog1了,能不能讓構造函數不記錄最近一次的傳值,而是在每次調用實例方法,我不覆蓋屬性,就用構造器上默認的屬性值呢?
每次給實例方法傳入不同的值,能不能不覆蓋構造函數上屬性的值?
Helenr
2019-03-13 17:12:46