87,910
社区成员
发帖
与我相关
我的任务
分享
function s(){};
s.prototype={
_cols:[],
drawTitle:function(titles){
var me=this;
titles=titles||[];
var c={name:'',width:10,type:'multi'};
titles.splice(0,0,c);//向titles数组在0位置上插入一个对象
for(var j=0;j<titles.length;j++){
this._cols[j]=titles[j];
}
}
}
var a=new s();
alert(s.prototype._cols.length)//原型的属性不会因实例中的属性变化而变化吧?
a.drawTitle([1,2,3]);
alert(s.prototype._cols.length)//但它确实变了!
function s(){};
s.prototype={
_cols:[],
drawTitle:function(titles){
var me=this;
titles=titles||[];
var c={name:'',width:10,type:'multi'};
titles.splice(0,0,c);//向titles数组在0位置上插入一个对象
for(var j=0;j<titles.length;j++){ //循环赋值
this._cols[j]=titles[j];
}
}
}
var a=new s();
a.drawTitle([1,2,3]);
alert(a._cols);
alert(s.prototype._cols)
delete a._cols; //揭示关键之所在
alert(a._cols);
alert(s.prototype._cols);
function s(){};
s.prototype={
_cols:[],
drawTitle:function(titles){
var me=this;
titles=titles||[];
var c={name:'',width:10,type:'multi'};
titles.splice(0,0,c);//向titles数组在0位置上插入一个对象
this._cols=titles; //直接赋值
}
}
var a=new s();
a.drawTitle([1,2,3]);
alert(a._cols);
alert(s.prototype._cols)
delete a._cols; //揭示关键之所在
alert(a._cols);
alert(s.prototype._cols);
function s(){};
s.prototype={
_cols:[],
drawTitle:function(titles){
for(var j=0;j<titles.length;j++){
this._cols[j]=titles[j];
}
}
}
var a=new s();
alert(s.prototype._cols.length)
a.drawTitle([1,2,3]);
alert(s.prototype._cols.length)
function s()
{
}
s.prototype = {
_cols: [],
init:function(_cols)
{
this._cols=_cols;
},
drawTitle: function(titles)
{
var me = this;
titles = titles || [];
var c = { name: '', width: 10, type: 'multi' };
titles.splice(0, 0, c); //向titles数组在0位置上插入一个对象
for (var j = 0; j < titles.length; j++)
{
this._cols[j] = titles[j];
}
}
}
var a = new s();
a.init([]);
alert(s.prototype._cols.length)//原型的属性不会因实例中的属性变化而变化吧?
a.drawTitle([1, 2, 3]);
alert(s.prototype._cols.length)//这个不变
alert(a._cols.length);
//这个变