当前位置:网站首页>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
边栏推荐
- 你想知道的ArrayList知识都在这
- 1202 character lookup
- 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
- 21. Delete data
- MySQL view tablespace and create table statements
- esRally国内安装使用避坑指南-全网最新
- The Vice Minister of the Ministry of industry and information technology of "APEC industry +" of the national economic and information technology center led a team to Sichuan to investigate the operat
- Onie supports pice hard disk
- Entity class design for calculating age based on birthday
- 24. Query table data (basic)
猜你喜欢
Machine learning - decision tree
Understanding of law of large numbers and central limit theorem
Make learning pointer easier (3)
A Closer Look at How Fine-tuning Changes BERT
Codeforces Global Round 19(A~D)
"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
Document 2 Feb 12 16:54
hcip--mpls
Nft智能合约发行,盲盒,公开发售技术实战--合约篇
wincc7.5下载安装教程(Win10系统)
随机推荐
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
Circuit breaker: use of hystrix
将 NFT 设置为 ENS 个人资料头像的分步指南
Résumé des diagrammes de description des broches de la série ESP
Document 2 Feb 12 16:54
[t31zl intelligent video application processor data]
指针和数组笔试题解析
Nacos Development Manual
08- [istio] istio gateway, virtual service and the relationship between them
MySQL view tablespace and create table statements
远程存储访问授权
Nc204382 medium sequence
【云原生】手把手教你搭建ferry开源工单系统
Upgrade tidb with tiup
Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
Data governance: 3 characteristics, 4 transcendence and 3 28 principles of master data
Migrate data from SQL files to tidb
Make learning pointer easier (3)
备份与恢复 CR 介绍
C语言自定义类型:结构体