refactoring of prototypes

This commit is contained in:
cloudhead 2010-03-07 23:38:10 -05:00
parent 07837a83a7
commit acd46cf7c6
2 changed files with 31 additions and 27 deletions

View File

@ -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 = {
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);
}
},
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(' ');
}
};
tree.Expression.prototype.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(' ');
};

View File

@ -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(', ');
};