Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default constructor for subclass now returns returned value from parent #1975

Closed
wants to merge 1 commit into from

Conversation

rymohr
Copy link

@rymohr rymohr commented Dec 26, 2011

This simple change makes it easy to implement identity maps (see included tests for example). Been needing something like this for my work with Backbone recently.

I left external constructors alone for now, as I don't fully understand their purpose as defined by the current test suite (external constructors return their own instances but are expected to behave as the calling class?):

  #1182: external constructors with bound functions 
  TypeError: Cannot call method 'call' of undefined
    at Function.<anonymous> (/Volumes/HD2/devel/opensource/coffee-script/test/classes.coffee:1042:30)
    at /Volumes/HD2/devel/opensource/coffee-script/Cakefile:203:12
    at Object.<anonymous> (/Volumes/HD2/devel/opensource/coffee-script/test/classes.coffee:1007:3)
    at Object.<anonymous> (/Volumes/HD2/devel/opensource/coffee-script/test/classes.coffee:1232:4)
    at Module._compile (module.js:432:26)
    at Object.run (/Volumes/HD2/devel/opensource/coffee-script/lib/coffee-script/coffee-script.js:66:25)
    at /Volumes/HD2/devel/opensource/coffee-script/Cakefile:271:22
    at Object.action (/Volumes/HD2/devel/opensource/coffee-script/Cakefile:285:12)
    at /Volumes/HD2/devel/opensource/coffee-script/lib/coffee-script/cake.js:39:26
    at Object.run (/Volumes/HD2/devel/opensource/coffee-script/lib/coffee-script/cake.js:62:21) 
  test/classes.js: line unknown, column unknown 
  function () {
    var A, B, fn, _class;
    fn = function() {
      return {
        one: 1
      };
    };
    B = (function() {

      function B() {
        var instance = this;
        return instance;
      }

      return B;

    })();
    A = (function() {

      function A() {
        this.method = __bind(this.method, this);
        var instance = this;
        instance = _class.apply(this, arguments);
        return instance;
      }

      _class = fn;

      A.prototype.method = function() {
        return this instanceof A;
      };

      return A;

    })();
    return ok((new A).method.call(new B));
  }

@michaelficarra
Copy link
Collaborator

Duplicate of #1970.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants