当前位置:网站首页>2022.7.22 js对象
2022.7.22 js对象
2022-07-23 21:08:00 【长寿的秘诀就是睡.】
一、对象的基本形式
1.除了原始值(基本类型),其他(函数、数组)都是对象
基础数据类型:Number、String、Boolean、Undefined、Null、Symbol。
2.语法
var car = {
color: 'red', //键值对
height: 1.8,
start: function () {
console.log('‘启动');
},
stop: function () {
console.log('熄火');
},
suv: true,
luntai:[1,2,3,4]
};- 在对象⾥的函数叫⽅法(methods)
- 对象里包含属性与值,属性的值可以是任意类型的
二、js对象中的常规操作
var car = {
color: "red",
height: 1.5,
start: function () {
console.log("启动");
},
end: function () {
console.log("熄火");
},
};
car.color = "blue"; //改
car.suv = true; //增
delete car.height; //删
console.log(car.color); //查
也可以使用方括号 [] 进行操作(不常用,比较复杂)
var car = {
color: "red",
height: 1.5,
start: function () {
console.log("启动");
},
end: function () {
console.log("熄火");
},
};
car["color"] = "blue"; //改
car["suv"] = true; //增
delete car["height"]; //删
console.log(car["color"]); //查三、怎么访问自身属性
可以通过 this 调用自身的属性和方法
var car = {
color: "red",
height: 1.5,
start: function () {
console.log("启动");
},
end: function () {
console.log("熄火" + this.color);
},
};
car.end();
四、创建对象的方式
1.直接声明一个对象并赋值
var car1 = new Object();
car1.color = "red";
car1.height = 1.9;
console.log(car1);
2.自定义构造函数
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);
边栏推荐
- Typescript Basics
- Vrrp+mstp configuration details [Huawei ENSP experiment]
- WinDbg实践--入门篇
- 比较关注证券公司究竟哪个佣金最低?请问网上开户安全么?
- Day 11: continue the basic configuration of BGP for day 10
- jsp+ssm+mysql实现的租车车辆管理系统汽车租赁
- Proof of green Tao theorem (2): generalization of von Neumann theorem
- Visual slam learning | basic chapter 01
- 高数下|二重积分的计算3|高数叔|手写笔记
- 【创建 Birthday Card 应用】
猜你喜欢

Himawari-8 数据介绍及下载方法

Opencv image processing Laplace pyramid

STM32C8t6 驱动激光雷达实战(二)

STM32c8t6驱动激光雷达(一)

实现生成订单30分钟未支付,则自动取消
![[attack and defense world web] difficulty four-star 12 point advanced question: confusion1](/img/ee/3ce5cc3004f9113bbf70e0c52ff4d9.png)
[attack and defense world web] difficulty four-star 12 point advanced question: confusion1
![[continuous update] collection of raspberry pie startup and failure series](/img/f3/706a625cdc214960e2d9ca0c7ea41c.jpg)
[continuous update] collection of raspberry pie startup and failure series

Chapter 3 business function development (creating clues)

prime_series_level-1

LU_ Asr01 voice module usage
随机推荐
Network learning infrared module, 8-way emission independent control
1061 Dating
一时跳槽一时爽,一直跳槽一直爽?
How to introduce your project experience in the interview
Modular development
Identify some positions in the parenthesis sequence
支付产品及其使用场景
【持续更新】树莓派启动与故障系列集锦
深入浅出边缘云 | 1. 概述
Green-Tao 定理的证明 (1): 准备, 记号和 Gowers 范数
第十二天:续第十一天(BGP相关知识)
It's good to change jobs for a while, and it's good to change jobs all the time?
Tell me the top ten securities companies? Is it safe to open an account online?
ES6 feature: Promise (custom encapsulation)
"Pulse" to the future! Huawei cloud Mrs helps smooth migration to the cloud
当我们在谈论陈春花和华为时,我们到底在讨论什么?
[cloud co creation] what magical features have you encountered when writing SQL every day?
Green-Tao 定理 (4): 能量增量方法
Addon plug-in 002 of CDR plug-in development - write an EXE program that can be run by double clicking in 1 minute
Vrrp+mstp configuration details [Huawei ENSP experiment]