第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

javascript高級程序設(shè)計(jì) 安全作用域構(gòu)造函數(shù) 問題

javascript高級程序設(shè)計(jì) 安全作用域構(gòu)造函數(shù) 問題

慕碼人8056858 2019-02-20 17:18:17
書上的解釋不太理解,求大神幫解釋下。為什么第一種沒有繼承到sides屬性// 創(chuàng)建作用域安全的構(gòu)造函數(shù)function Polygon(sides) {    if (this instanceof Polygon) {        console.log('this', this);        this.sides = sides;        this.getArea = function(){            return 0;        }    } else {        return new Polygon(sides);    }}// 非作用域安全的構(gòu)造函數(shù)function Rectangle(width, height) {    Polygon.call(this, 2);      this.width = width;    this.height = height;    this.getArea = function (){        return this.width * this.height;    }}let rect = new Rectangle(5,10);console.log(rect.sides);為什么rect沒有繼承到side屬性而通過原型就可以Rectangle.prototype = new Polygon();let rect = new Rectangle(2,4);console.log(rect.sides);// 2
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 420 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號