Use this:
var A = function(){},
B = function(){};
A.prototype.b = new B();
B.prototype.sayHi = function(){
alert("hi");
}
var obj=new A();
obj.b.sayHi();
質問
I have an object like this
var a={
b:{
sayHi:function(){
alert("hi");
}
}
}
I want to convert it into function name spacing using prototypes. How can I convert ? I tried following. but not working
var a=function(){};
a.prototype.b=function(){};
b.prototype.sayHi=function(){
alert("hi");
}
var obj=new a();
obj.b.sayHi();
Any Help ?
解決
Use this:
var A = function(){},
B = function(){};
A.prototype.b = new B();
B.prototype.sayHi = function(){
alert("hi");
}
var obj=new A();
obj.b.sayHi();