Created
July 9, 2013 22:49
-
-
Save mrcsparker/5962016 to your computer and use it in GitHub Desktop.
Playing with formula evaluation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Eval data is coming from a secure source. | |
var columns = {}; | |
columns['_A1'] = "this.A2"; | |
columns['_A2'] = "3"; | |
columns['_A3'] = "this.A1 + this.A2"; | |
Object.defineProperty(columns, "A1", { | |
get: function() { | |
return eval(columns['_A1']) | |
} | |
}); | |
Object.defineProperty(columns, "A2", { | |
get: function () { | |
return columns['_A2']; | |
}, | |
set: function (val) { | |
columns['_A2'] = val; | |
} | |
}); | |
Object.defineProperty(columns, "A3", { | |
get: function () { | |
return eval(columns['_A3']) | |
} | |
}); | |
console.log(columns); | |
console.log(columns.A1); | |
console.log(columns.A3); | |
columns.A2 = 10; | |
console.log(columns.A1); | |
console.log(columns.A3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment