当前位置:网站首页>Yyds dry goods inventory three JS source code interpretation eventdispatcher
Yyds dry goods inventory three JS source code interpretation eventdispatcher
2022-07-06 08:08:00 【Xin Ran】
stay three.js in , Found a lot of use Object.assign and Object.create Method , And many constructors have inheritance EventDispatcher, Now for EventDispatcher Study the method
1. Source code
function EventDispatcher() {} // Constructors
Object. assign( EventDispatcher. prototype, {
addEventListener: function ( type, listener) {
if ( this. _listeners === undefined) {
this. _listeners = {};
}
var listeners = this. _listeners;
if ( listeners[ type] === undefined) {
listeners[ type] = [];
}
if ( listeners[ type]. indexOf( listener) === - 1) {
listeners[ type]. push( listener);
}
},
hasEventListener: function ( type, listener) {
if ( this. _listeners === undefined) {
return false;
}
var listeners = this. _listeners;
return listeners[ type] !== undefined && listeners[ type]. indexOf( listener) !== - 1;
},
removeEventListener: function ( type, listener) {
if ( this. _listeners === undefined) {
return;
}
var listeners = this. _listeners;
var listenerArray = listeners[ type];
if ( listenerArray !== undefined) {
var index = listenerArray. indexOf( listener);
if ( index !== - 1) {
listenerArray. splice( index, 1);
}
}
},
dispatchEvent: function ( event) {
if ( this. _listeners === undefined) {
return;
}
var listeners = this. _listeners;
var listenerArray = listeners[ event. type];
if ( listenerArray !== undefined) {
event. target = this;
var array = listenerArray. slice( 0);
for ( var i = 0, l = array. length; i < l; i ++) {
array[ i]. call( this, event);
}
}
}
});
function Texture() {} // Constructors
Texture. prototype = Object. assign( Object. create( EventDispatcher. prototype), {
test: function() {
console. log( 'test')
}
})
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
2. Test code
const tt = new Texture()
console. log( 'tt', tt)
- 1.
- 2.
3. Core code description
If you make the following code changes
The output result at this time is as follows :
4. summary
- three.js Many constructors in will inherit EventDispatcher Constructors
- Object.assign Use of methods
- Object.create Use of methods
- three.js Event monitoring in is similar to other frameworks , for example jQuery The same is true , It's the same principle
边栏推荐
- Vit (vision transformer) principle and code elaboration
- 好用的TCP-UDP_debug工具下载和使用
- "Friendship and righteousness" of the center for national economy and information technology: China's friendship wine - the "unparalleled loyalty and righteousness" of the solidarity group released th
- 1204 character deletion operation (2)
- Database basic commands
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- Document 2 Feb 12 16:54
- 使用 BR 备份 TiDB 集群数据到兼容 S3 的存储
- Transformer principle and code elaboration
- [research materials] 2022 China yuancosmos white paper - Download attached
猜你喜欢
2.10transfrom attribute
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
861. Score after flipping the matrix
好用的TCP-UDP_debug工具下载和使用
Asia Pacific Financial Media | "APEC industry +" Western Silicon Valley invests 2trillion yuan in Chengdu Chongqing economic circle to catch up with Shanghai | stable strategy industry fund observatio
Sanzi chess (C language)
21. Delete data
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
24. Query table data (basic)
随机推荐
[Yugong series] February 2022 U3D full stack class 010 prefabricated parts
Migrate data from SQL files to tidb
Pyqt5 development tips - obtain Manhattan distance between coordinates
PHP - Common magic method (nanny level teaching)
图像融合--挑战、机遇与对策
[redis] Introduction to NoSQL database and redis
Data governance: Data Governance under microservice architecture
TiDB备份与恢复简介
"Designer universe" APEC design +: the list of winners of the Paris Design Award in France was recently announced. The winners of "Changsha world center Damei mansion" were awarded by the national eco
Nacos Development Manual
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
数据治理:数据质量篇
MFC 给列表控件发送左键单击、双击、以及右键单击消息
Onie supports pice hard disk
Wireshark grabs packets to understand its word TCP segment
(lightoj - 1410) consistent verbs (thinking)
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
Hackathon ifm
Analysis of Top1 accuracy and top5 accuracy examples
Go learning notes (3) basic types and statements (2)