Sign in to follow this  
coter

How to extend EventEmitter?

Recommended Posts

ooh! ooh!... I learned a new thing!  :D

DisplayObject.prototype = Object.create(EventEmitter.prototype);

If you follow the prototype chain on a DisplayObject you will see the EventEmitter interface 

 

 

__proto__EventEmitter

_eventsundefined

addListeneron(event, fn, context)

constructorEventEmitter()

emitemit(event, a1, a2, a3, a4, a5)

listenerslisteners(event, exists)

offremoveListener(event, fn, context, once)

onon(event, fn, context)

onceonce(event, fn, context)

removeAllListenersremoveAllListeners(event)

removeListenerremoveListener(event, fn, context, once)

setMaxListenerssetMaxListeners()

 

So, you should be able to use a DisplayObject as a dispatcher.

Or you can just do this...

var myEventEmitter = Object.create(Object.getPrototypeOf(Object.getPrototypeOf(new PIXI.DisplayObject())))

Share this post


Link to post
Share on other sites

 

ooh! ooh!... I learned a new thing!  :D

DisplayObject.prototype = Object.create(EventEmitter.prototype);

If you follow the prototype chain on a DisplayObject you will see the EventEmitter interface 

 

 

__proto__EventEmitter

_eventsundefined

addListeneron(event, fn, context)

constructorEventEmitter()

emitemit(event, a1, a2, a3, a4, a5)

listenerslisteners(event, exists)

offremoveListener(event, fn, context, once)

onon(event, fn, context)

onceonce(event, fn, context)

removeAllListenersremoveAllListeners(event)

removeListenerremoveListener(event, fn, context, once)

setMaxListenerssetMaxListeners()

 

So, you should be able to use a DisplayObject as a dispatcher.

Or you can just do this...

var myEventEmitter = Object.getPrototypeOf(Object.getPrototypeOf(new PIXI.DisplayObject())) 

It's too tiring.Easier sources to correct. Just EventEmitter not in public. I wonder why the authors hid...

Share this post


Link to post
Share on other sites

It's too tiring.Easier sources to correct. Just EventEmitter not in public. I wonder why the authors hid...

 

We didn't hide it, it is EventEmitter3 (https://github.com/primus/eventemitter3). Just use it in your module. We expose it in the next version so that it is easier to access, but you can just use the module yourself if you want.

 

If you extend any of the Pixi display objects then you will have an emitter anyway though. Anything that extends DO is an emitter.

Share this post


Link to post
Share on other sites
We didn't hide it, it is EventEmitter3 (https://github.com/p...s/eventemitter3).

 

I use the Google translator, which distorts the speech. I didn't mean that You hide using eventemitter3.
I am saying that if you don't add so -
 
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.PIXI = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function (global){require('./polyfill');var core = module.exports = require('./core');//core.EventEmitter = require('eventemitter3'); <<<<<<<<<<<<<<core.extras = require('./extras');core.filters = require('./filters');core.interaction = require('./interaction');core.loaders = require('./loaders');core.mesh = require('./mesh');core.loader = new core.loaders.Loader();Object.assign(core, require('./deprecation'));global.PIXI = core;}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})},{"eventemitter3":11,"./core":29,"./deprecation":78,"./extras":85,"./filters":102,"./interaction":117,"./loaders":120,"./mesh":126,"./polyfill":130}],2:[function(require,module,exports){
 
I can't import it to my code. And he needed me for a single custom model.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.