Skip to content

Instantly share code, notes, and snippets.

@BobGneu
Created May 12, 2014 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobGneu/269ce6d7840a88b8a4d5 to your computer and use it in GitHub Desktop.
Save BobGneu/269ce6d7840a88b8a4d5 to your computer and use it in GitHub Desktop.
if (typeof Object.addEventListener !== 'function')
{
Object.addEventListener = function (name, fn)
{
// If this object has yet to have any events attached, create a new object.
if (!this.events)
this.events = {};
// If this event listing has not yet been notified of this event, create a new array.
this.events[name] = this.events[name] || [];
// add this callback to the list
this.events[name].push(fn);
};
}
if (typeof Object.dispatchEvent !== 'function')
{
Object.dispatchEvent = function (ev)
{
// if there are no events, we don't care
if (!this.events)
return;
// if this event has no listeners registered, we don't care either.
if (!this.events[ev.Name])
return;
// add this callback to the list
this.events[ev.Name].forEach(function (element)
{
element(ev.detail);
});
};
}
var CustomEvent = function (name, params)
{
params = params ||
{
bubbles: false,
cancelable: false,
detail: undefined
};
this.Name = name;
this.bubbles = params.bubbles || false;
this.detail = params.detail ||
{};
this.cancelable = params.cancelable || false;
};
var test = Object.create(Object);
test.addEventListener("initialized", function (details)
{
game.log("Inititialized.", v8.version, v8.bindingVersion);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment