js 继承带来的苦果!
JScript codevar Point = function() { this. x = 1; this. y = 1; this.setPoint = function(px, py) { x = px; y = py; }; this.showPoint = function() { alert("x=\t" + x + "\ny=\t" + y); };};var ColorPoint = function(){ this.color = "#FFFFFF"; Point.call(this); //this 指的是Obj};var p1= new ColorPoint();p1.setPoint(5,5);p1.showPoint(); //这里是 "x = 5 y = 5"alert(p1.x); //这里是 1 //没想到啊!
//气死我了,没想到啊!
------解决方案--------------------
this.setPoint = function(px, py) { this.x = px; this.y = py; };
this.showPoint = function() { alert("x=\t" + this.x + "\ny=\t" + this.y); };
------解决方案--------------------
你这样子搞,x和y都是全局变量,因为你Point函数里没有初始化。
------解决方案--------------------
围观
------解决方案--------------------