type | example | effect |
---|---|---|
uninitialized array | x = new Array(10) | create an array with 10 elements |
initialized array | x = new Array(10, 20, 30) | create an array with 3 elements: 10, 20, and 30 |
initialized array | x = [10, 20, 30]; | create an array with 3 elements: 10, 20, and 30 |
|
|
|
|
|
function Account(cust_name, initial_deposit, date) { this.name = cust_name; this.balance = initial_deposit; this.origination_date = date; } Account.prototype.creditBalance = functjion(amount) { this.balance += amount; }
For example:
function CDAccount(cust_name, initial_deposit, date, interestRate) { Account.call(this, cust_name, initial_deposit, date); this.interestRate = interestRate; } CDAccount.prototype = object.create(Account.prototype); CD.prototype.constructor = CDAccount; // Add a new method to credit interest to the account CDAccount.prototype.creditInterest = function() { this.balance *= (1 + this.interestRate); return this.balance; } let newAcct = CDAccount("brad", 100, "2021-03-05", 0.05); console.log(newAcct.creditInterest()); // prints 105
class Account constructor (cust_name, initial_deposit, date) { this.name = cust_name; this.balance = initial_deposit; this.origination_date = date; } creditBalance(amount) { this.balance += amount; } }
class CDAccount extends Account { constructor (cust_name, initial_deposit, date, interestRate) { super(cust_name, initial_deposit, date); this.interestRate = interestRate; } creditInterest() { this.balance *= (1 + this.interestRate); return this.balance; } }