为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

largeQ 2018-11-21 15:11:33
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呢?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 407 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号