1

I have an model object;

building= model("tb_buildings");
building.myFunction() = function(){return false;};

Initially this object has no methods, I am trying to created a method for it called myFunction() and assign it a value of false; I tried the anonymous function approach but it give me an error;

Cannot assign a value to a function

Is this possible?

Saad A
  • 1,135
  • 2
  • 21
  • 46
  • 1
    *create a method for it called myFunction()* FWIW, the actual name of the function is "myFunction", not "myFunction()". By adding the parenthesis, you are actually *invoking* the function (with no parameters), rather than assigning something to a variable named: "myFunction". Hence the error "....Cannot assign a value to a function". – Leigh Dec 01 '15 at 18:18

1 Answers1

8

To set a variable to be a function you should

building.myFunction = function(){ return false; };
Leigh
  • 28,765
  • 10
  • 55
  • 103
James A Mohler
  • 11,060
  • 15
  • 46
  • 72