function Field(w,h){
this.width = w?w:10;
this.height = h?h:20;
this.show = function(){
var f = create("div","f")
f.style.width=this.width*20+'px';
f.style.height=this.height*20+'px';}
this.findFull = function(){
for(var l=0;l<this.height;l++){
var s=0;
for(var i=0;i<this.width;i++){
s+=this[l*this.width+i]?1:0;}//this[]这种用法很不明白
if(s==this.width){
this.removeLine(l);}}}
javascriptthisfunctionjsthsi[]
this.width = w?w:10;
this.height = h?h:20;
this.show = function(){
var f = create("div","f")
f.style.width=this.width*20+'px';
f.style.height=this.height*20+'px';}
this.findFull = function(){
for(var l=0;l<this.height;l++){
var s=0;
for(var i=0;i<this.width;i++){
s+=this[l*this.width+i]?1:0;}//this[]这种用法很不明白
if(s==this.width){
this.removeLine(l);}}}
javascriptthisfunctionjsthsi[]
js的寻址是这样的,如果a是一个数,那么就作为this对象的第a个属性来引用。
而且如果这里this指代的是数组,那么就是数组了呗,本身数组和对象没什么区别……
js的寻址是这样的,如果a是一个数,那么就作为this对象的第a个属性来引用。function a(){
this.e = "ee";
this.b = "bb";
this.c = "cc";
this.d = "dd";
alert(this[1])
}
a();
打印出来是undefined啊
你可以直接 object.key 来访问
也可以用object[key]来动态访问
数组你可以看成是一种特别的object。
js的寻址是这样的,如果a是一个数,那么就作为this对象的第a个属性来引用。function a(){
this.e = "ee";
this.b = "bb";
this.c = "cc";
this.d = "dd";
alert(this[1])
}
a();
打印出来是undefined啊貌似不是这么用的?不过不讨论这个问题,你代码里这个this貌似指代的是一个数组吧。
for(var l=0;l<this.height;l++){
var s=0;
for(var i=0;i<this.width;i++){
s+=this[l*this.width+i]?1:0;}这里的this应该是指代一个类似二维数组的东西吧……感觉像是你那个filed类,很明显这两个循环是在扫this的每个点。
var o2={};
o2.length=0;
o2.push= function (a) {
this[this.length] = a;
this.length++;
}o2.push("Is object?");
var toString = Object.prototype.toString
alert(o2[0]);
alert(toString.call(o1));
alert(toString.call(o2));