Object 【object】
Everything is object and objects are empty
Function arrays are all objects
Objects: Complex data structures
Define an object:
A. Define an object literally
var obj = {
name: "Sun Wukong".age: 1000.address: "Water Curtain Cave of Huaguo Mountain".wife: {
name: "Purple Glow Fairy".age: 5000,},son: {
name: Sun Wufan
},
hobby: ["Eat the peach"."Playing a stick"."Orion"].say: function () {
console.log("Where is Master Sand??");
},
eat: function (food) {
console.log("Eat" + food);
return "I am the Monkey King."; }}Copy the code
B. Construct an object using new
var obj1 = new Object(a);// Access the key-value pairs in the object
// How to use
console.log(obj.name, obj.wife.name);
// Get with []
console.log(obj["name"]);
// Call a function in the object
obj.say();
console.log(obj.eat("Peach"));Copy the code
C. Object classification:
Math Date Array Number String Boolean
The host object DOM BOM needs to be in the browser
3, ** custom object **
Objects: Properties (blue) and methods (API purple)
Are you seeing anyone? Anyway, XIAobian I don’t have, ha ha ha!! Everything is an object, and objects are empty. Master the object, is to master the knowledge!!