javaScript prototype
jsオブジェクトの原型に対するテスト:
prototype
function baseClass(){
//
this.showMsg=function(){
console.log("baseClass::showMsg");
}
}
function extendClass(){
//
this.upd=function(){
console.log("this.upd");
}
}
extendClass.prototype=new baseClass(); // base extendClass, extendClass showMsg
extendClass.prototype.updFun=function(){
console.log("updFun is called");
} // extendClass updFun, extendClass , , , ,
//
extendClass.updClass=function(args){
console.log("updClass");
}
// , json, extendClass , baseas
extendClass.prototype.updd={
baseas:(function(args){
//args window
console.log("has in based");
console.log(args);
})(window),
// , ,
base2:function(args){
console.log("has in badsed2222");
console.log(args);
}
}
var instance=new extendClass();
extendClass.prototype.updFun();
// instance.updClass, ,
extendClass.updClass();
//
instance.showMsg();
// , extendClass.prototype.updFun()
instance.updFun();
// upd
instance['upd'].call();
// xbig, , {}
var xbig= xbig||{};
console.log("xbig:"+JSON.stringify(xbig)); //xbig:{}
// xbig ins json ,fb
xbig.ins={fa:"1",fb:function(){
console.log("fb");
}}
xbig.ins.module= {upd:function(args){
//call this, args, , this, ,
console.log(this);
console.log("I`d like to do");
console.log("args:"+args);
}};
xbig.ins.module['upd'].call({a:1},"somesthing1");
var xbig2= xbig||{};
console.log("xbig2:"+JSON.stringify(xbig2)); //xbig2:{"ins":{"fa":"1","module":{}}}
xbig2.ins.module['upd'].call(instance,"somesthing2");
prototype 1