Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Domain feature must not clobber EventEmitter#domain field. #3922

@ashtuchkin

Description

@ashtuchkin
// Constructor of some model class.
function WebSite(domain) {
    this.domain = domain;
}

// Inheriting from EventEmitter.
var EventEmitter = require('events').EventEmitter;
WebSite.prototype = new EventEmitter();

// Create instance. 
var website = new WebSite("google.com");

// Add event handler.
website.on("ping", function() { console.log("pong"); });

// Try to emit event.
website.emit("ping");

> TypeError: Object google.com has no method 'enter'
    at EventEmitter.emit (events.js:80:19)
    ...
// What? How? Hmm.. 

What happens here is that EventEmitter uses a field named 'domain' to store its domain, and tries to call this.domain.enter(), which is neither documented, nor expected.

Solution: At least rename it to '_domain' (like '_events', internal by convention).

Background: I have a Mongoose model with field 'domain' and cannot rename it easily as the database depends on it. Therefore I have no choice but to get back to Node v0.6, until this bug is fixed. Please, help!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions