diff --git a/lib/nodes.js b/lib/nodes.js index 79fd0b65..b56a910e 100644 --- a/lib/nodes.js +++ b/lib/nodes.js @@ -1668,7 +1668,7 @@ } }); UTILITIES = { - 'extends': "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.__superClass__ = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n }", + 'extends': "function(child, parent) {\n var ctor = function(){ };\n ctor.prototype = parent.prototype;\n child.prototype = new ctor();\n child.prototype.constructor = child;\n if (typeof parent.extended === \"function\") parent.extended(child);\n child.__superClass__ = parent.prototype;\n }", hasProp: 'Object.prototype.hasOwnProperty', slice: 'Array.prototype.slice' }; diff --git a/src/nodes.coffee b/src/nodes.coffee index e62ce019..2a2263f1 100644 --- a/src/nodes.coffee +++ b/src/nodes.coffee @@ -1479,9 +1479,10 @@ UTILITIES: { function(child, parent) { var ctor = function(){ }; ctor.prototype = parent.prototype; - child.__superClass__ = parent.prototype; child.prototype = new ctor(); child.prototype.constructor = child; + if (typeof parent.extended === "function") parent.extended(child); + child.__superClass__ = parent.prototype; } """ diff --git a/test/test_classes.coffee b/test/test_classes.coffee index b1c5a347..5dfc0cc7 100644 --- a/test/test_classes.coffee +++ b/test/test_classes.coffee @@ -183,3 +183,26 @@ c: new Child c.method 1, 2, 3, 4 ok c.args.join(' ') is '1 2 3 4' + +# Test `extended` callback. +class Base + @extended: (subclass) -> + for key, value of @ + subclass[key]: value + +class Element extends Base + @fromHTML: (html) -> + node: "..." + new @(node) + + constructor: (node) -> + @node: node + +ok Element.extended is Base.extended +ok Element.__superClass__ is Base.prototype + +class MyElement extends Element + +ok MyElement.extended is Base.extended +ok MyElement.fromHTML is Element.fromHTML +ok MyElement.__superClass__ is Element.prototype