This commit is contained in:
yimi 2017-09-18 09:48:32 +00:00
parent caf102463a
commit 7dc9866681

View File

@ -47,21 +47,22 @@ function DEFNODE(type, props, methods, base) {
if (arguments.length < 4) base = AST_Node;
if (!props) props = [];
else props = props.split(/\s+/);
var ctor = function (props) {
if (props) {
var ctor = this.CTOR;
do {
var self_props = ctor.SELF_PROPS;
for (var i = self_props.length; i;) {
var k = self_props[--i];
this[k] = props[k];
}
} while (ctor = ctor.BASE)
if (this.initialize) {
this.initialize();
}
}
}
var code = "return function AST_" + type + "(props) {\
if (props) {\
var ctor = this.CTOR;\
do {\
var self_props = ctor.SELF_PROPS;\
for (var i = self_props.length; i;) {\
var k = self_props[--i];\
this[k] = props[k];\
}\
} while (ctor = ctor.BASE);\
if (this.initialize) {\
this.initialize();\
}\
}\
}";
var ctor = new Function(code)();
var proto = base && new base;
if (proto) {
ctor.prototype = proto;