Please enable JavaScript.
Coggle requires JavaScript to display documents.
Object (Create a object (Using object literal, With keyword "new"…
Object
Create a object
-
-
Define an object constructor, and then create object of the constructor type
Types
Single object
-
We read property
-
-
Read a property that does not exist, we get value undefined
-
Syntax
-
Many value: var person = {
name: "Nhi",
age: 18
}
Object property
Can be changed, added, deleted
Accessing JS properties
- Using "." (dot) : object.property
- Using []: object["property"]
-
Object methods
-
Can be: primitive values, other objects and function
-
This keyword
-
When use alone, this refer to the global object [object window]
Accessing object methods
- Method is executed when it is invoked with ()
- Example: method()
Constructor
-
This
- In constructor, this do not have a value
- The value of this will become the new object when a new object is created
-
Adding property
-
function NameConstructor(options) {
this.data = options.data,
this.name = options. name
}
Adding method
-
function NameConstructor(options) {
this.name = options.name,
this.age = options.age
}
NameConstructor.prototype.name = function() {statement}
- Objects have property (key & value)
-
- Value : is any JavaScript value