Skip to content

Override order is reversed when providing functions instead of Objects #20

@kafoso

Description

@kafoso

In test.js, exports.testOverride verifies that the "youngest" Object (or "class") overrides the same-name function of its parent (or "base"). This test of course works.

However, if the prop argument is a function, the override order is reversed. See example below.

exports.testOverrideOfFunctions = function(test) {
    test.expect(2);
    var A = inherit(function(){
      this.method = function() {
          return 'A';
      };
    });
    var B = inherit(A, function(){
      this.method = function() {
          return 'B';
      };
    });

    test.equal(new A().method(), 'A');
    test.equal(new B().method(), 'B');
    test.done();
};

The above test fails. See output below.

✖ testOverrideOfFunctions

AssertionError: 'B' == 'A'
    at Object.equal (/usr/local/lib/node_modules/nodeunit/lib/types.js:83:39)
    at Object.exports.testOverrideOfFunctions (/home/kafoso/git/inherit/test/test.js:142:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/nodeunit/lib/core.js:236:16)
    at /usr/local/lib/node_modules/nodeunit/lib/core.js:236:16
    at Object.exports.runTest (/usr/local/lib/node_modules/nodeunit/lib/core.js:70:9)
    at /usr/local/lib/node_modules/nodeunit/lib/core.js:118:25
    at /usr/local/lib/node_modules/nodeunit/deps/async.js:513:13
    at iterate (/usr/local/lib/node_modules/nodeunit/deps/async.js:123:13)
    at /usr/local/lib/node_modules/nodeunit/deps/async.js:134:25
    at /usr/local/lib/node_modules/nodeunit/deps/async.js:515:17

Naturally, the prop argument should be an Object per your documentation. However, it would be a nice addition.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions