mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 11:31:20 -05:00
class B extends A calls A.extended(B)
This commit is contained in:
@@ -1668,7 +1668,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
UTILITIES = {
|
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',
|
hasProp: 'Object.prototype.hasOwnProperty',
|
||||||
slice: 'Array.prototype.slice'
|
slice: 'Array.prototype.slice'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1479,9 +1479,10 @@ UTILITIES: {
|
|||||||
function(child, parent) {
|
function(child, parent) {
|
||||||
var ctor = function(){ };
|
var ctor = function(){ };
|
||||||
ctor.prototype = parent.prototype;
|
ctor.prototype = parent.prototype;
|
||||||
child.__superClass__ = parent.prototype;
|
|
||||||
child.prototype = new ctor();
|
child.prototype = new ctor();
|
||||||
child.prototype.constructor = child;
|
child.prototype.constructor = child;
|
||||||
|
if (typeof parent.extended === "function") parent.extended(child);
|
||||||
|
child.__superClass__ = parent.prototype;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -183,3 +183,26 @@ c: new Child
|
|||||||
c.method 1, 2, 3, 4
|
c.method 1, 2, 3, 4
|
||||||
ok c.args.join(' ') is '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
|
||||||
|
|||||||
Reference in New Issue
Block a user