Javascript Variables Have One of Two Scopes:: Global Scope Local Scope Within A Function
Javascript Variables Have One of Two Scopes:: Global Scope Local Scope Within A Function
scopes:
Global scope
Local scope within a function
such as:
Math
JSON
such as:
parseInt()
parseFloat()
isNan()
objects in JavaScript:
var employee1 = new Object();
var employee2 = {};
an object:
var employee1 = {};
employee1.name = "John Smith";
employee1.age = 21;
employee1.salary = 10000;
employee1.payRise = function(amount) {
// Inside a method, "this" means the current object.
this.salary += amount;
return this.salary;
}
Using Constructors
Constructor functions define the shape of
objects
They create and assign properties for the target
object
var Account = function (id, name) {
this.id
id;
The =
target
object is referenced by the this
this.name
= name;
keyword
this.balance = 0;
this.numTransactions = 0;
};
Using Prototypes
All objects created by using a constructor
Account.prototype = {
deposit: function(amount) {
this.balance += amount;
this.numTransactions++;
},
// Plus other methods
};