In my JavaScript I have an object instance called "View". I want to add a function to this object. The function looks something like
function csiSelectValueRestriction (columnName) {
//... <a rather long and involved function>
}
Ultimately I want to be able to use the function in the following way:
var result = View.csiSelectValueRestriction ("bldgs");
What is the simplest way to accomplish this?
James Allardice
166k22 gold badges335 silver badges316 bronze badges
asked Apr 3, 2013 at 14:53
user2135970
8152 gold badges12 silver badges23 bronze badges
3 Answers 3
Just assign the function to the property;
View.csiSelectValueRestriction = csiSelectValueRestriction;
answered Apr 3, 2013 at 14:58
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
user2135970
Yeah, that worked great. It couldn't have been simpler - thx.
This should work if you want to add a function to an existing instance
View['csiSelectValueRestriction'] = function (columnName) { ... ... }
answered Apr 3, 2013 at 14:54
user18428
1,20111 silver badges17 bronze badges
Comments
var View = {
someProperty: 'someVal',
csiSelectValueRestriction: function(columnName) {
//JS logic
}
};
or View.csiSelectValueRestriction = function(columnName) { ... }
answered Apr 3, 2013 at 14:54
Rob
4,94712 gold badges53 silver badges57 bronze badges
Comments
lang-js