常晏綺Javascript物件導向方法是物件的函數

物件導向設計OOP=Object-Oriented Programming

主詞subject受詞object東方的oriental

id=identity,身分證id card, division區塊,段落

.方法get()是取得對應的值,功能同字典

dict.get(s1.code)從dict字典取得索引為s1.code的值

常晏綺以上的程式碼

<H1>物件導向設計OOP=Object-Oriented Programming</H1>
主詞subject受詞object東方的oriental
<P id="cat"></P>
<P id="dog"></P>
<P>id=identity,身分證id card, division區塊,段落</P>
<script>//Javascript註解二斜線//Python註解#
dict =new Map([["2303","聯電"],["2330","台積電"],["2880","華南金"]]);//宣告配對(字典)
class Stock{      //宣告類別
  constructor(code, shares, price){//建構子constructor
    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;
st = dict.get(s1.code)+' 股數 '+s1.shares.toString()+'<BR>'+dict.get(s2.code)+' 股數 '+s2.shares;
document.getElementById('dog').innerHTML = st;
</script>
.方法get()是取得對應的值,功能同字典
<P>dict.get(s1.code)從dict字典取得索引為s1.code的值<P>


加上美國股票的程式碼

<h1>物件導向設計OOP=Object-Oriented Programming</h1>
主詞subject受詞object東方的oriental
<p id="cat"></p>
<p id="dog"></p>
<p>id=identity,身分證id card, division區塊,段落</p>
<script>//Javascript註解二斜線//Python註解#
dict =new Map([["2303","聯電"],["2330","台積電"],["2880","華南金"],['AAPL','蘋果公司'],['C','花旗銀行'],['T','美國電話電報']]);//宣告配對(字典)
class Stock{      //宣告類別
  constructor(code, shares, price){//建構子constructor
    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
s3 = new Stock("C", 100, 1000); //建構子Stock建構s1
s4 = new Stock("T", 1000, 30); //建構子Stock建構s2

st = s1.code+' 股數 '+s1.shares.toString()+'<BR>'+s2.code.toString()+' 股數 '+s2.shares;
document.getElementById('cat').innerHTML = st;
st = dict.get(s3.code)+' 股數 '+s3.shares.toString()+'<BR>'+dict.get(s4.code)+' 股數 '+s4.shares;
document.getElementById('dog').innerHTML = st;
</script>

留言

  1. https://chang-yam-ci.blogspot.com/2025/04/word-file-processing-in-pythonpythonword.html
    https://chang-yam-ci.blogspot.com/2025/04/javascript.html
    402.https://chang-yam-ci.blogspot.com/2025/04/pythontkentrystringvar.html
    326.https://chang-yam-ci.blogspot.com/2025/03/idejupyterpython.html
    319.https://chang-yam-ci.blogspot.com/2025/03/javascriptpython.html
    https://chang-yam-ci.blogspot.com/2025/04/htmlbuttononclick.html
    312.https://chang-yam-ci.blogspot.com/2025/03/blog-post.html
    維基百科https://chang-yam-ci.blogspot.com/2025/03/w3schoolspython.html
    第一次上課嵌入二影片。https://chang-yam-ci.blogspot.com/2025/02/blog-post_46.html

    回覆刪除

張貼留言

這個網誌中的熱門文章

期末財金程式設計588Python_Javascript網路執行_EXCEL_IRR二分法

Python tkinter繪圖對比EXCEL