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?

3 Answers 3

1

Just assign the function to the property;

View.csiSelectValueRestriction = csiSelectValueRestriction;
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) { ... ... }

Comments

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

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

Comments

Your Answer

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.