We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
物件導向(Object Oriented Programming 簡稱OOP)的概念是將現實生活中的各種複雜的情況,抽象成各個物件,然後由這些物件進行分工與合作來模擬現實生活的情況。
對於物件的描述
例如: 一輛車變成物件的樣子
const car = { name: 'toyota', color: 'black', amount: 700000 tax: function(countryTax) { return amount * countryTax } }
那我們想要造一台黃色的bmw的車子就必須又要重複定義這個結構
const bmwCar = { name: 'bmw', color: 'yellow', amount: 1400000 tax: function(countryTax) { return amount * countryTax } }
那有什麼辦法能夠解決重複結構的問題呢?
構造函數(constructor)使我們不需要再重複定義物件,是製造物件的模板
let Car = function(name,color,amount,countryTax){ this.name = name this.color = color this.amount = amount this.tax = function(){ return amount * countryTax } }
構造函數與一般函數來說是沒什麼差別的,只是呼叫方式的不同,構造函數必須使用new來調用一個實例
let toyotaCar = new Car('toyota','black',700000,1.2)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
物件導向(Object Oriented Programming 簡稱OOP)的概念是將現實生活中的各種複雜的情況,抽象成各個物件,然後由這些物件進行分工與合作來模擬現實生活的情況。
對於物件的描述
例如: 一輛車變成物件的樣子
那我們想要造一台黃色的bmw的車子就必須又要重複定義這個結構
那有什麼辦法能夠解決重複結構的問題呢?
構造函數(constructor)使我們不需要再重複定義物件,是製造物件的模板
構造函數與一般函數來說是沒什麼差別的,只是呼叫方式的不同,構造函數必須使用new來調用一個實例
The text was updated successfully, but these errors were encountered: