当前位置:网站首页>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
边栏推荐
- Grayscale upgrade tidb operator
- Machine learning - decision tree
- 数据治理:微服务架构下的数据治理
- Secure captcha (unsafe verification code) of DVWA range
- [redis] Introduction to NoSQL database and redis
- 使用 Dumpling 备份 TiDB 集群数据到兼容 S3 的存储
- MFC sends left click, double click, and right click messages to list controls
- Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center
- Golang DNS 随便写写
- Data governance: misunderstanding sorting
猜你喜欢
![[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems](/img/6d/282d904810807810adb06b071fb39b.jpg)
[factorial inverse], [linear inverse], [combinatorial counting] Niu Mei's mathematical problems

"Designer universe": "benefit dimension" APEC public welfare + 2022 the latest slogan and the new platform will be launched soon | Asia Pacific Financial Media
![[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached](/img/35/898a8086bc35462b0fcb9e6b58b86b.jpg)
[research materials] 2022 enterprise wechat Ecosystem Research Report - Download attached

A Closer Look at How Fine-tuning Changes BERT

21. Delete data
![[research materials] 2021 Research Report on China's smart medical industry - Download attached](/img/c8/a205ddc2835c87efa38808cf31f59e.jpg)
[research materials] 2021 Research Report on China's smart medical industry - Download attached

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

好用的TCP-UDP_debug工具下载和使用
![[untitled]](/img/38/bc025310b9742b5bf0bd28c586ec0d.jpg)
[untitled]

Hcip day 16
随机推荐
珠海金山面试复盘
(lightoj - 1410) consistent verbs (thinking)
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
"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
861. Score after flipping the matrix
【T31ZL智能视频应用处理器资料】
1202 character lookup
Tidb backup and recovery introduction
Erc20 token agreement
How to use information mechanism to realize process mutual exclusion, process synchronization and precursor relationship
数据治理:微服务架构下的数据治理
二叉树创建 & 遍历
你想知道的ArrayList知识都在这
Step by step guide to setting NFT as an ens profile Avatar
Vit (vision transformer) principle and code elaboration
CAD ARX gets the current viewport settings
Golang DNS write casually
Convolution, pooling, activation function, initialization, normalization, regularization, learning rate - Summary of deep learning foundation
图像融合--挑战、机遇与对策
ESP系列引脚說明圖匯總