tnhu / jsface

Small, fast, elegant, powerful, and cross platform JavaScript OOP library. Support main(), singleton, super call, private, mixins, plugins, AOP and more.
MIT License
301 stars 46 forks source link

Error using EventEmitter api #19

Closed hightechlofi closed 9 years ago

hightechlofi commented 10 years ago

I am learning jsface, and have written a test class to debug the structure of how I want to write my classes before I code them full blown. Everything works great, unless I try to add EventEmitters to the object. I get the following error

f.updateConfig("new config"); ^ TypeError: Object [object Object] has no method 'updateConfig'

By event code is as follows:

var jsface = require("jsface"),
    Class = jsface.Class,
    extend = jsface.extend,
    b = require("bonescript"),
    util = require("util"),
    EventEmitter = require("events").EventEmitter;

var face = Class({

    constructor: function(opts, callback) {

      console.log("object created - " + opts);

      this.name = opts;

      //callback(null);

    },

    updateConfig: function(opts, callback) {

      console.log("config updated - " + opts);

      //callback(null);

    },

    setPower: function(power, callback) {

      console.log("set power - " + power);

      //callback(null);

    },

    setState: function(state, callback) {

      console.log("state set - " + state);

      //callback(null);
    },

    getData: function(callback) {

      console.log("data requested");

      callback(null, "data object");

    },

    getConfig: function(callback) {

      console.log("config requested");

      callback(null, "config object");

    },

    $statics: {

        actions: {

            subscribe: function() {

                console.log("subscribe called");

            },

            setState: function() {

                console.log("setState action called");

            },

            setPower: function() {

                console.log("setPower action called");

            },

            updateConfig: function() {

                console.log("updateConfig action called");

            },

            getConfig: function() {

                console.log("getConfig action called");

            }

        }

    }

});

module.exports = face;

//util.inherits(face, EventEmitter);

If I comment out the util.inherits line (as shown), I can access all of the class methods and everything works as expected (just no eventemitters). I have used this eventemitter api on non jsFace objects and it works well. Any ideas? Any alternatives to the EventEmitter?

Thanks.