当前位置:网站首页>2022.7.22 JS object
2022.7.22 JS object
2022-07-23 21:10:00 【The secret of longevity is sleep】
One 、 Basic form of object
1. In addition to the original value ( Basic types ), other ( function 、 Array ) Are all objects
Basic data type :Number、String、Boolean、Undefined、Null、Symbol.
2. grammar
var car = {
color: 'red', // Key value pair
height: 1.8,
start: function () {
console.log('‘ start-up ');
},
stop: function () {
console.log(' Stalling ');
},
suv: true,
luntai:[1,2,3,4]
};- In object ⾥ The function of is called ⽅ Law (methods)
- Objects contain attributes and values , The value of an attribute can be of any type
Two 、js General operations in objects
var car = {
color: "red",
height: 1.5,
start: function () {
console.log(" start-up ");
},
end: function () {
console.log(" Stalling ");
},
};
car.color = "blue"; // Change
car.suv = true; // increase
delete car.height; // Delete
console.log(car.color); // check
You can also use square brackets [] To operate ( Not commonly used , More complicated )
var car = {
color: "red",
height: 1.5,
start: function () {
console.log(" start-up ");
},
end: function () {
console.log(" Stalling ");
},
};
car["color"] = "blue"; // Change
car["suv"] = true; // increase
delete car["height"]; // Delete
console.log(car["color"]); // check 3、 ... and 、 How to access its own attributes
Can pass this Call its own properties and methods
var car = {
color: "red",
height: 1.5,
start: function () {
console.log(" start-up ");
},
end: function () {
console.log(" Stalling " + this.color);
},
};
car.end();
Four 、 How to create objects
1. Declare an object directly and assign values
var car1 = new Object();
car1.color = "red";
car1.height = 1.9;
console.log(car1);
2. Custom constructors
function Factory(color, height, suv) {
this.color = color;
this.height = height;
this.suv = suv;
}
var car1 = new Factory("red", 1.8, true);
console.log(car1);
边栏推荐
- KubeVela离线安装
- Too complete, it is recommended to collect! What can sap bring to the enterprise?
- Stm32c8t6 driven lidar (I)
- High numbers | calculation of triple integral 1 | high numbers | handwritten notes
- Green-Tao 定理的证明 (2): Von Neumann 定理的推广
- Minimum spanning tree: Kruskal
- From which dimensions can we judge the quality of code? How to have the ability to write high-quality code?
- 1061 Dating
- 最小生成树:Prim
- 【Scratch画图100例】图46-scratch绘制花朵 少儿编程 scratch编程画图案例教程 考级比赛画图集训案例
猜你喜欢

【isprint函数判断字符是否可输出】

Network learning infrared module, 8-way emission independent control

The common interfaces of Alipay are uniformly encapsulated and can be used directly for payment parameters (applicable to H5, PC, APP)

信号的理解

Chapter 2 回归

TCP half connection queue and full connection queue (the most complete in History)

MySQL(3)
![[attack and defense world web] difficulty four-star 12 point advanced question: flatscience](/img/fc/6648116f1bb47f1888035796fa5a58.png)
[attack and defense world web] difficulty four-star 12 point advanced question: flatscience

Opencv image processing Laplace pyramid

MySql的DDL和DML和DQL的基本语法
随机推荐
如何在面试中介绍自己的项目经验
[cloud co creation] what magical features have you encountered when writing SQL every day?
[Yunxiang book club No. 13] Chapter IV packaging format and coding format of audio files
How to introduce your project experience in the interview
Junior intern, ByteDance, after sharing, has been offered
Green-Tao 定理的证明 (2): Von Neumann 定理的推广
scala编程(中级进阶实验应用)
Major upgrade of openim - group chat reading diffusion model release group management function upgrade
Green-Tao 定理 (4): 能量增量方法
LeetCode_376_摆动序列
第十一天:续第十天BGP的基本配置
高数下|二重积分的计算4|高数叔|手写笔记
大三实习生,字节跳动面经分享,已拿Offer
Microservice architecture vs single service architecture [what can Huawei cloud service do in the microservice mode]
Minimum spanning tree: prim
如何在面試中介紹自己的項目經驗
深入浅出边缘云 | 1. 概述
Too complete, it is recommended to collect! What can sap bring to the enterprise?
MySQL(3)
Proof of green Tao theorem (2): generalization of von Neumann theorem