当前位置:网站首页>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
边栏推荐
- Redis list detailed explanation of character types yyds dry goods inventory
- Database basic commands
- [Yugong series] creation of 009 unity object of U3D full stack class in February 2022
- [KMP] template
- File upload of DVWA range
- Asia Pacific Financial Media | art cube of "designer universe": Guangzhou community designers achieve "great improvement" in urban quality | observation of stable strategy industry fund
- esRally国内安装使用避坑指南-全网最新
- "Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
- 升级 TiDB Operator
- Learn Arduino with examples
猜你喜欢

esRally国内安装使用避坑指南-全网最新

NFT smart contract release, blind box, public offering technology practice -- contract

. Net 6 learning notes: what is NET Core

Analysis of pointer and array written test questions

Make learning pointer easier (3)
![DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist](/img/17/415e66d67afb055e94a966de25c2bc.png)
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist

IP lab, the first weekly recheck

File upload of DVWA range

Secure captcha (unsafe verification code) of DVWA range

A Closer Look at How Fine-tuning Changes BERT
随机推荐
Document 2 Feb 12 16:54
Data governance: metadata management
P3047 [usaco12feb]nearby cows g (tree DP)
wincc7.5下载安装教程(Win10系统)
Pyqt5 development tips - obtain Manhattan distance between coordinates
[research materials] 2021 Research Report on China's smart medical industry - Download attached
Secure captcha (unsafe verification code) of DVWA range
1202 character lookup
Transformer principle and code elaboration
数据治理:主数据的3特征、4超越和3二八原则
Qualitative risk analysis of Oracle project management system
23. Update data
861. Score after flipping the matrix
Risk planning and identification of Oracle project management system
[research materials] 2021 China online high growth white paper - Download attached
Sanzi chess (C language)
从 TiDB 集群迁移数据至另一 TiDB 集群
Leetcode question brushing record | 203_ Remove linked list elements
Data governance: misunderstanding sorting
好用的TCP-UDP_debug工具下载和使用