0

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

3 Answers 3

1

Just assign the function to the property;

View.csiSelectValueRestriction = csiSelectValueRestriction;
answered Apr 3, 2013 at 14:58
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah, that worked great. It couldn't have been simpler - thx.
1

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

Comments

0
var View = {
 someProperty: 'someVal',
 csiSelectValueRestriction: function(columnName) {
 //JS logic
 }
};

or View.csiSelectValueRestriction = function(columnName) { ... }

answered Apr 3, 2013 at 14:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.