当前位置:网站首页>对象的访问机制及其他
对象的访问机制及其他
2022-06-27 00:33:00 【InfoQ】
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayHi = function () { console.log('hello world') }
// 使用 Person 创建一个对象
let p1 = new Person('Jack', 18);
console.log(p1);
// 当我访问 p1.name 的时候, 自己就有
console.log(p1.name);
p1.sayHi();
// 再次创建一个实例化对象
let p2 = new Person('Rose', 20);
p2.sayHi(); function Tabs(ele, options = {}) {
// 拿到出现选项卡的范围
this.ele = document.querySelector(ele)
// 找到 btns
this.btns = this.ele.querySelectorAll('ul > li')
// 找到 tabs
this.tabs = this.ele.querySelectorAll('ol > li')
// 初始化一下 options
this.options = options
this.change()
}
Tabs.prototype.change = function () {
// 操作的是当前实例的 btns 和 tabs
// this 就是当前实例, 我们就要给 this.btns 的每一个添加点击事件
this.btns.forEach((item, index) => {
item.addEventListener(this.options.type || 'click', () => {
this.btns.forEach((t, i) => {
t.className = ''
this.tabs[i].className = ''
})
// 给对应的添加类名
item.className = 'active'
this.tabs[index].className = 'active'
})
})
}
new Tabs('.box2', { type: 'mouseover' })
new Tabs('.box3');
let t1 = new Tabs('.box', { type: 'click' })
console.log(t1);1. var arr = [] , Array 的实例
2. var obj = {} , Object 的实例
3. var p1 = new Person() , Person 的实例
4. var time = new Date() , Date 的实例
5. var fn = function () {} , Function 的实例
6. Person.prototype , Object 的实例
7. Array.prototype , Objec 的实例 原型链
判断数据类型
- instanceof
了解对象
for in 循环
对象自己的方法
边栏推荐
- CPU的异常处理
- 如何写好测试用例以及go单元测试工具testify简单介绍
- Operating instructions and Q & A of cec-i China learning machine
- Special topic II on mathematical physics of the sprint strong foundation program
- How to convert an old keyboard into a USB keyboard and program it yourself?
- 大白话高并发(一)
- ESP32实验-自建web服务器配网02
- 解决STC8G1K08程序不能运行的问题和端口配置
- Xiaobai looks at MySQL -- installing MySQL in Windows Environment
- 数据库面试题+sql语句解析
猜你喜欢

Special topic II on mathematical physics of the sprint strong foundation program

滑环选型选购时需要注意的技巧

如何把老式键盘转换成USB键盘并且自己编程?

Live review | Ziya &ccf TF: Discussion on software supply chain risk management technology under cloud native scenario

史上最难618,TCL夺得电视行业京东和天猫份额双第一

Lwip之ARP模块实现

30《MySQL 教程》MySQL 存储引擎概述

Central Limit Theorem

Lambda表达式

Gaussian and Summary Stats
随机推荐
用代码生成流程图,Markdown的使用方法
XSS攻击笔记(上)
Sword finger offer 10- ii Frog jumping on steps
TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘
气液滑环与其他滑环的工作原理有什么区别
超越锂电池——未来电池的概念
Generate flow chart with code, and how to use markdown
Other service registration and discovery
剑指 Offer 10- II. 青蛙跳台阶问题
Bootstrapblazor + FreeSQL actual combat chart usage (2)
史上最难618,TCL夺得电视行业京东和天猫份额双第一
Esp32-solo development tutorial to solve config_ FREERTOS_ UNICORE problem
Statistical Hypothesis Testing
05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
idea 热启动失效解决方案
这3个并发编程的核心,竟然还有人不知道?
Employment prospect of GIS and remote sensing specialty and ranking selection of universities in 2022
LeetCode 142. 环形链表 II
What are the skills and methods for slip ring installation
数据库面试题+sql语句解析