Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6846711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:39:26+00:00 2026-05-27T00:39:26+00:00

Same as this question, but Prototype library specific: I’ve got a Browser class, and

  • 0

Same as this question, but Prototype library specific:

I’ve got a Browser class, and I want to fire and observe custom events for this class. Prototype’s custom event system only lets me bind to and fire events on DOM elements. Here’s my first idea as to an alternative:

function Browser() {
    this.event = new Element('span');
}
Browser.prototype.render = function() {
    this.event.fire('browser:render');
}

var browser = new Browser();
browser.event.observe('browser:render', function() { ... });

Is there a better way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:39:27+00:00Added an answer on May 27, 2026 at 12:39 am

    Thanks in part to Frits van Campen’s advice, I made my own that serves my needs, a little more sophisticated than Frits’ sample.

    function EventManager(target) {
        var target = target || window,
            events = {};
        this.observe = function(eventName, cb) {
            if (events[eventName]) events[eventName].push(cb);
            else events[eventName] = new Array(cb);
            return target;
        };
        this.stopObserving = function(eventName, cb) {
            if (events[eventName]) {
                var i = events[eventName].indexOf(cb);
                if (i > -1) events[eventName].splice(i, 1);
                else return false;
                return true;
            }
            else return false;
        };
        this.fire = function(eventName) {
            if (!events[eventName]) return false;
            for (var i = 0; i < events[eventName].length; i++) {
                events[eventName][i].apply(target, Array.prototype.slice.call(arguments, 1));
            }
        };
    }
    

    Then I can do:

    Function Browser() {
        this.event = new EventManager(this);
    }
    Browser.prototype.render = function() {
        this.event.fire("render");
    }   
    
    browser = new Browser();
    browser.event.observe("render", function() { alert("Rendered"); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The same as this question but for java Update Based on the comments and
[This question is related to but not the same as this one .] My
[This question is related to but not the same as this one .] If
Pretty much the same as this question. But I can't seem to get this
This is the same question as this but I'm looking for a classic ASP
This question is related to (but perhaps not quite the same as): Does Django
I have an ObjectDataSource (but perhaps this question is the same for all kinds
This is related to the this question and the answer maybe the same but
This is driving me nuts. I believe I asked this exact same question, but
This is the same question for older version of Scala, but they say that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.