当前位置:网站首页>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
边栏推荐
- Huawei cloud OBS file upload and download tool class
- "Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
- 从 SQL 文件迁移数据到 TiDB
- Helm install Minio
- Notes on software development
- Migrate data from SQL files to tidb
- On why we should program for all
- 【T31ZL智能视频应用处理器资料】
- Pangolin Library: control panel, control components, shortcut key settings
- The State Economic Information Center "APEC industry +" Western Silicon Valley will invest 2trillion yuan in Chengdu Chongqing economic circle, which will surpass the observation of Shanghai | stable
猜你喜欢
ROS learning (IX): referencing custom message types in header files
Machine learning - decision tree
matplotlib. Widgets are easy to use
File upload of DVWA range
Data governance: 3 characteristics, 4 transcendence and 3 28 principles of master data
你想知道的ArrayList知识都在这
2.10transfrom attribute
Asia Pacific Financial Media | designer universe | Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers
22. Empty the table
在 uniapp 中使用阿里图标
随机推荐
On why we should program for all
Golang DNS 随便写写
数据治理:误区梳理篇
NFT smart contract release, blind box, public offering technology practice -- contract
JS select all and tab bar switching, simple comments
esRally国内安装使用避坑指南-全网最新
[Yugong series] creation of 009 unity object of U3D full stack class in February 2022
Huawei cloud OBS file upload and download tool class
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached
[nonlinear control theory]9_ A series of lectures on nonlinear control theory
Make learning pointer easier (3)
[research materials] 2021 China online high growth white paper - Download attached
Nacos Development Manual
22. Empty the table
Esrally domestic installation and use pit avoidance Guide - the latest in the whole network
21. Delete data
ESP系列引脚说明图汇总
从 TiDB 集群迁移数据至另一 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
"Designer universe" Guangdong responds to the opinions of the national development and Reform Commission. Primary school students incarnate as small community designers | national economic and Informa