代码拉取完成,页面将自动刷新
//正式,注意作用域和浅复制,new的区别
// (function () {
var maintest3=1;
let maintest2 =2;
var Class={
create: function(){
return function(){
this.initialize.apply(this,arguments);//改变函数执行的上下文。区别:bind 是返回改变后的函数,不会立即执行。 apply call 可以传数组。
}
}
}
var DicApplyAdd_Scrap = Class.create();//这里仅仅是返回了一个函数 。//= Innolux.Page.DicApplySelect_Scrap;;
//区别 The Object.create() method creates a new object, using an existing object as the prototype of the newly created object.
// Parameters
// proto https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create
// The object which should be the prototype of the newly-created object.
// 技术分析
// propertiesObject Optional
// If specified and not undefined, an object whose enumerable own properties (that is, those properties defined upon itself and not enumerable properties along its prototype chain) specify property descriptors to be added to the newly-created object, with the corresponding property names. These properties correspond to the second argument of Object.defineProperties().
// 抽象基类
DicApplyAdd_Scrap.prototype={//增加属性与方法。
initialize:function(){
//this.name = name;
// this.doSomething
},
getName:function(){
// return this.name;
return "base class?"
},
doSomething:function(){
console.log("base class do somethin fn");
},
// curr_strategy:function default_strategy() {
// console.log("default_strategy");
// }
}
//context上下文
// Context -- In example code: Shipping
// maintains a reference to the current Strategy object
// supports interface to allow clients to request Strategy calculations
// allows clients to change Strategy
let Context = function () {
this.strategy = null;
}
Context.prototype = {//?
setStrategy:function (strategy) {
this.strategy=strategy;
},
exeStrategy:function (params) {
this.strategy.doSomething();
}
}
// 改进:先new一个基类。但这样不符合oop,不应该new 基类的。
var client = new DicApplyAdd_Scrap();
// strategys
let vendor_s = function ( ) {
return Object.assign({...client},{ //...// 空的。。。
doSomething: function () {
console.log("具体策略vendor做something");
}// 覆盖掉 DicApplyAdd_Scrap基类的dosomething方法
});//返回修改后的目标对象
}
let GW_s = function ( ) {
return Object.assign({...client},{
doSomething: function () {
console.log("具体策略GW做something");
}
});
}
const status_is_vendor = new vendor_s();
const status_is_GW = new GW_s();
status_is_vendor.doSomething();
status_is_GW.doSomething();
status_is_GW.prototype.doSomething();//还是默认的没有被改变。字面量?
const status_switch =new Context();//必须new 下面才有setStrategy这个方法。
status_switch.setStrategy(status_is_vendor);
status_switch.exeStrategy();
console.log(client.getName());
// });
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。