日期:2014-05-16 浏览次数:20399 次
<html>
<head>
<script>
function test(o){
this.options = {
t : {
name:null,
value:null
},
ts : []
};
this.extends = function(obj1,obj2){
for (var prop in obj2){
obj1[prop] = obj2[prop];
}
}
this.getT = function(thObject){
var th = this.options.t;
for(var prop in thObject){
th[prop] = thObject[prop];
}
return th;
}
this.addThToColl = function(th){
this.options.ts.push(th);
}
this.extends(this.options,o);
this.init=function(){
for(var i=0;i<this.options.ts.length;i++){
alert(this.options.ts[i].name);
}
}
}
var kk = new test({});
kk.addThToColl(kk.getT({name:"ff"}));
kk.addThToColl(kk.getT({name:"gg"}));
kk.init();
</script>
</head>
</html>
<html>
<head>
<script>
function test(o){
this.options = {
t : {
name:null,
value:null
},
ts : []
};
this.extends = function(obj1,obj2){
for (var prop in obj2){
obj1[prop] = obj2[prop];
}
}
this.getT = function(thObject){
this.options.t= {
name:null,
value:null
}
var th = this.options.t;
for(var prop in thObject){
th[prop] = thObject[prop];
}
return th;
}
this.addThToColl = function(th){
this.options.ts.push(th);
}
this.extends(this.options,o);
this.init=function(){
for(var i=0;i<this.options.ts.length;i++){
alert(this.options.ts[i].name);
}
}
}
var kk = new test({});
kk.addThToColl(kk.getT({name:"ff"}));
kk.addThToColl(kk.getT({name:"gg"}));
kk.init();
</script>
</head>
</html>