当前位置:网站首页>Object access mechanism and others
Object access mechanism and others
2022-06-27 01:00:00 【InfoQ】
function Person(name, age) {
this.name = name;
this.age = age;
}
Person.prototype.sayHi = function () { console.log('hello world') }
// Use Person Create an object
let p1 = new Person('Jack', 18);
console.log(p1);
// When I visit p1.name When , I have
console.log(p1.name);
p1.sayHi();
// Create an instantiated object again
let p2 = new Person('Rose', 20);
p2.sayHi();
function Tabs(ele, options = {}) {
// Get the scope of the tab that appears
this.ele = document.querySelector(ele)
// find btns
this.btns = this.ele.querySelectorAll('ul > li')
// find tabs
this.tabs = this.ele.querySelectorAll('ol > li')
// Initialize it options
this.options = options
this.change()
}
Tabs.prototype.change = function () {
// It operates on the current instance btns and tabs
// this This is the current example , We're going to give this.btns For each add click event
this.btns.forEach((item, index) => {
item.addEventListener(this.options.type || 'click', () => {
this.btns.forEach((t, i) => {
t.className = ''
this.tabs[i].className = ''
})
// Add the class name to the corresponding
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 Example
2. var obj = {} , Object Example
3. var p1 = new Person() , Person Example
4. var time = new Date() , Date Example
5. var fn = function () {} , Function Example
6. Person.prototype , Object Example
7. Array.prototype , Objec Example
Prototype chain
Judge data type
- instanceof
Understanding the object
for in loop
The object's own way
边栏推荐
- 05 | 规范设计(下):commit 信息风格迥异、难以阅读,如何规范?
- Basic introduction to C program structure Preview
- 2022年地理信息系统与遥感专业就业前景与升学高校排名选择
- Generate flow chart with code, and how to use markdown
- JS library for number formatting
- ESP32实验-自建web服务器配网02
- Hid device descriptor and keyboard key value corresponding coding table in USB protocol
- USB协议中HID设备描述符以及键盘按键值对应编码表
- Flink practical problems (VII): no watermark (watermarks are only available eventtime is used)
- How to use ch423? Cheap domestic IO expansion chip
猜你喜欢
How to measure the thickness of glass substrate by spectral confocal
Gaussian and Summary Stats
Lwip之定时机制
Esp32 experiment - self built web server distribution network 02
Beyond lithium battery -- the concept of battery in the future
Law of Large Numbers
About Random Numbers
统计无向图中无法互相到达点对数[经典建邻接表+DFS统计 -> 并查集优化][并查集手册/写的详细]
Statistical Hypothesis Testing
Moher College - SQL injection vulnerability test (error reporting and blind note)
随机推荐
How to write test cases and a brief introduction to go unit test tool testify
The [MySQL] time field is set to the current time by default
Interface test framework practice (I) | requests and interface request construction
这10款文案神器帮你速码,做自媒体还担心写不出文案吗?
3 - wire SPI Screen Drive
气液滑环与其他滑环的工作原理有什么区别
These 10 copywriting artifacts help you speed up the code. Are you still worried that you can't write a copywriting for US media?
XML learning notes
2022年地理信息系统与遥感专业就业前景与升学高校排名选择
基于SSMP的宠物医院管理系统
Review the old and know the new -- constant renewal at normal temperature
Redis detailed tutorial
【Mysql】时间字段默认设置为当前时间
Lambda表达式
Esp32 experiment - self built web server distribution network 02
How to control the quality of HD slip ring in the production process
世界很大,有人把二维码纹在脖子上
目前哪个证券公司炒股开户是最好最安全的?
matlab数据类型 —— 字符型
超越锂电池——未来电池的概念