refactoring of prototypes

browser
cloudhead 15 years ago
parent 07837a83a7
commit acd46cf7c6

@ -1,22 +1,24 @@
if (typeof(window) === 'undefined') { var tree = require(require('path').join(__dirname, '..', '..', 'less', 'tree')); }
tree.Expression = function Expression(value) { this.value = value };
tree.Expression.prototype.eval = function (env) {
if (this.value.length > 1) {
return new(tree.Expression)(this.value.map(function (e) {
return e.eval(env);
}));
} else {
return this.value[0].eval(env);
}
};
tree.Expression.prototype.toCSS = function (env) {
var evaled;
evaled = this.value.map(function (e) {
if (e.eval) {
e = e.eval(env);
tree.Expression.prototype = {
eval: function (env) {
if (this.value.length > 1) {
return new(tree.Expression)(this.value.map(function (e) {
return e.eval(env);
}));
} else {
return this.value[0].eval(env);
}
return e.toCSS ? e.toCSS(env) : e;
});
return evaled.join(' ');
},
toCSS: function (env) {
var evaled;
evaled = this.value.map(function (e) {
if (e.eval) {
e = e.eval(env);
}
return e.toCSS ? e.toCSS(env) : e;
});
return evaled.join(' ');
}
};

@ -20,16 +20,18 @@ tree.Value = function Value(value) {
this.value = value;
this.is = 'value';
};
tree.Value.prototype.eval = function (env) {
if (this.value.length === 1) {
return this.value[0].eval(env);
} else {
return this;
tree.Value.prototype = {
eval: function (env) {
if (this.value.length === 1) {
return this.value[0].eval(env);
} else {
return this;
}
},
toCSS: function (env) {
return this.value.map(function (e) {
return e.toCSS ? e.toCSS(env) : e;
}).join(', ');
}
};
tree.Value.prototype.toCSS = function (env) {
return this.value.map(function (e) {
return e.toCSS ? e.toCSS(env) : e;
}).join(', ');
};

Loading…
Cancel
Save