楊雅竹javascript物件導向python物件導向
物件導向程式設計
Javascript指令new Constructor產生新的instance案例
s1.shares.toString()=案例sa的屬性shares內建方法toString()轉成字串,原來的數字被轉成字串string才可以和其他字串相加
在原來的輸出指令插入+dict.get(s1.code)+從字典dict查詢s1.code的結果
JAVASCRIPT程式碼
<DVI ID='cat'></DVI>
<SCRIPT>
class Stock{ //宣告類別
constructor(code, shares, price){
this.code = code;
this.shares = shares;
this.price = price;}
}
s1 = new Stock("2330", 100, 1000); //建構子Stock建構s1
s2 = new Stock("2880", 1000, 30); //建構子Stock建構s2
st = s1.code+' 股數 '+s1.shares.toString()+'<BR>'+s2.code.toString()+' 股數 '+s2.shares;
document.getElementById('cat').innerHTML = st;
JAVASCRIPT程式碼加入配對(字典)指令
dict =new Map([["2303","聯電"],["2330","台積電"],["2880","華南金"]]);//宣告配對(字典)
sin cos.https://yangyami.blogspot.com/2025/05/javascriptsincoscanvasfont.html
回覆刪除https://yangyami.blogspot.com/2025/04/oopobject-oriented-programming.html
https://yangyami.blogspot.com/2025/04/spyderdocxword.html
https://yangyami.blogspot.com/2025/04/javascriptpython.html
https://yangyami.blogspot.com/2025/04/javascriptpython_14.html