js作用域安全的构造函数的一个问题

function Polygon(sides){

                if(this instanceof Polygon){

                    this.sides=sides;

                    this.getArea=function(){

                        return 0;

                    }

                }else{

                    return new Polygon(sides);

                }

            }

            

            function  Rectangle(wifth,height){

                Polygon.call(this,2);

                this.width=this.width;

                this.height=height;

                this.getArea=function(){

                    return this.width * this.height;

                };

            }

            

            var rect=new Rectangle(5,10);

            alert(rect.sides); //undefined

这段代码是js高程三中P598-599的一个例子
我想问的是为什么alert的是undefined呢?

largeQ
浏览 408回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript