亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

求解釋下面js中的枚舉類型的代碼是什么意思?

求解釋下面js中的枚舉類型的代碼是什么意思?

徐錦杰 2017-03-03 23:39:07
<!DOCTYPE?html> <html> <head> <meta?charset="utf-8"> <title></title> <script?type="text/javascript"> function?inherit(p){ if(p==null)?throw?TypeError(); if(Object.create)?return?Object.create(p); var?t=typeof?p; if(t!=="object"&&?t!=="function")?throw?TypeError(); function?f(){}; f.prototype=p; return?new?f(); } function?enumeration(namesToValues){ var?enumeration=function(){throw?"can't?instantiate?enumeration"}; var?proto=enumeration.prototype={ constructor:enumeration, toString:function(){return?this.name;}, valueOf:function(){return?this.value;}, toJSON:function(){return?this.name;} }; enumeration.values=[]; for(name?in?namesToValues){ var?e=inherit(proto);? e.name=name;????? e.value=namesToValues[name];? enumeration[name]=e; enumeration.values.push(e); } enumeration.foreach=function(f,c){ for?(var?i=0;i<this.values.length;i++) f.call(c,this.values[i]); }; return?enumeration;// } var?Coin=enumeration({Penny:1,Nickel:5,Dime:10,Quarter:25}); var?c=Coin.Dime; console.log(c?instanceof?Coin); console.log(c.constructor==?Coin); console.log(c); console.log(Coin.Nickel); console.log(Coin.values); console.log(Coin.Nickel==5);? console.log(Coin.Nickel+Coin.Penny);?????//==6 </script> </head> <body> </body> </html>這里Coin.Nickel,Coin.Penny都是類屬型,值是一個對象,為什么可以相加呢?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 1965 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號