当前位置:网站首页>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
边栏推荐
- 让学指针变得更简单(三)
- Yu Xia looks at win system kernel -- message mechanism
- Notes on software development
- Understanding of law of large numbers and central limit theorem
- 从 CSV 文件迁移数据到 TiDB
- Make learning pointer easier (3)
- Hackathon ifm
- Restore backup data on S3 compatible storage with br
- 24. Query table data (basic)
- 从 TiDB 集群迁移数据至另一 TiDB 集群
猜你喜欢

ESP系列引脚说明图汇总

Database basic commands

24. Query table data (basic)

It's hard to find a job when the industry is in recession

Epoll and IO multiplexing of redis

ESP series pin description diagram summary

C语言 - 位段
![[research materials] 2021 live broadcast annual data report of e-commerce - Download attached](/img/a6/74da2f44c7b6b22fed2f8e41a55988.jpg)
[research materials] 2021 live broadcast annual data report of e-commerce - Download attached

Artcube information of "designer universe": Guangzhou implements the community designer system to achieve "great improvement" of urban quality | national economic and Information Center

Understanding of law of large numbers and central limit theorem
随机推荐
Analysis of pointer and array written test questions
Pyqt5 development tips - obtain Manhattan distance between coordinates
ESP系列引脚說明圖匯總
hcip--mpls
从 SQL 文件迁移数据到 TiDB
flask返回文件下载
CAD ARX gets the current viewport settings
Hackathon ifm
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
1204 character deletion operation (2)
Vit (vision transformer) principle and code elaboration
Uibehavior, a comprehensive exploration of ugui source code
National economic information center "APEC industry +": economic data released at the night of the Spring Festival | observation of stable strategy industry fund
DataX self check error /datax/plugin/reader/_ drdsreader/plugin. Json] does not exist
Nft智能合约发行,盲盒,公开发售技术实战--拼图篇
24. Query table data (basic)
Introduction to backup and recovery Cr
让学指针变得更简单(三)
C语言 - 位段
升级 TiDB Operator