Three. js source code annotation (21) Core/EventDispatcher. js

Source: Internet
Author: User

Three. js source code annotation (21) Core/EventDispatcher. js

 


I also just started learning. Sorry for the errors in many places.

The following code is a comment on the Core/EventDispatcher. JS file in the THREE. js source code file.

More updates in: https://github.com/omni360/three.js.sourcecode


/*** Https://github.com/mrdoob/eventdispatcher.js/ * // EventDispatcher the base class of all runtime classes for the event that can be scheduled. it is used to manage listening functions and is embedded on Object3D objects. this method is automatically triggered when an event occurs in Object3D. /// you can register a function by calling the addEventListener () method of the object that schedules the event to process running events. *////EventDispatcherTHREE. eventDispatcher = function () {}/************************************* * ****** the functions provided by the Vector4 object. **************************************** /THREE. eventDispatcher. prototype = {constructor: THREE. eventDispatcher, // constructor, returns a reference to the function for creating the EventDispatcher object. /* // The apply method binds the current base class to the parameter Object object and adds the base class method to the Object object Object. *////Apply///Apply: function (object) {object. addEventListener = THREE. eventDispatcher. prototype. addEventListener; // Add the addEventListener () method to the object. object. hasEventListener = THREE. eventDispatcher. prototype. hasEventListener; // Add the hasEventListener () method to the object. object. removeEventListener = THREE. eventDispatcher. prototype. removeEventListener; // Add the removeEventListener () method to the object. object. dispatchEvent = THREE. eve NtDispatcher. prototype. dispatchEvent; // Add the dispatchEvent () method to the object .}, /* // The addEventListener method registers the event listener object using the EventDispatcher object, to enable the listener to receive Event Notifications // The JavaScript code in the air runtime registers the event listener for the events defined by the air api using this method. For other JavaScript events (such as the onload event of the DOM body object), // you can use the standard event processing technology like the content running in the browser. After an event listener is successfully registered, you cannot change its priority by calling addEventListener. /// To change the priority of the listener, you must first call removeListener (). Then, you can use the new priority to register the listener again. /// NOTE: if you no longer need an event listener, you can call removeEventListener () to delete it. Otherwise, memory problems may occur. Because the garbage collector does not delete objects that still contain references, it does not automatically delete objects that use registered event listeners from the memory. /// NOTE: When you copy an EventDispatcher instance, the added event listener is not copied. (If an event listener is required for a newly created node, the listener must be attached after the node is created .) However, if you move the EventDispatcher instance, the added event listener will also move. *////AddEventListener///Event Type ///The listener function that processes the event. This function must accept the Event object as its unique parameter and cannot return any results. The function can have any name 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) ;}},/* // The addEventListener method checks whether the EventDispatcher object registers any listener for a specific event type. In this way, you can determine where the EventDispatcher object changes the processing of the event type in the event stream hierarchy. *////AddEventListener///Event Type ///Listener object to be checked ///
 
  
Returns true or false.
 HasEventListener: function (type, listener) {if (this. _ listeners = undefined) return false; var listeners = this. _ listeners; if (listeners [type]! = Undefined & listeners [type]. indexOf (listener )! =-1) {return true; // if the specified type of listener has been registered, the value is true;} return false; // otherwise, the value is false. },/* // RemoveEventListener method to delete the listener from the EventDispatcher object. If no matching listener is registered with the EventDispatcher object, the call to this method has no effect. *////RemoveEventListener///Event Type ///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); // The deleted listener object }},/* // The dispatchEvent method schedules the event to the event stream. The event target is the EventDispatcher object for which the dispatchEvent () method is called. *////DispatchEvent///The Event object scheduled to the Event stream. If an event is being rescheduled, a clone of the event is automatically created. After an event is scheduled, its target attribute cannot be changed. Therefore, you must create a new copy of the event to be rescheduled. DispatchEvent: function (event) {if (this. _ listeners = undefined) return; var listeners = this. _ listeners; var listenerArray = listeners [event. type]; if (listenerArray! = Undefined) Export event.tar get = this; var array = []; var length = listenerArray. length; for (var I = 0; I <length; I ++) {array [I] = listenerArray [I] ;}for (var I = 0; I <length; I ++) {array [I]. call (this, event );}}}};


Wuji (http://blog.csdn.net/omni360)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.


The following code is a comment on the Core/EventDispatcher. JS file in the THREE. js source code file.

More updates in: https://github.com/omni360/three.js.sourcecode

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.