0

I have javascript script code here. When I execute my code as it is then it does not trigger func_two function. But when I change following code in func_one

    if (this.remove) {
        this.func_two;
    }

to this

    if (this.remove) {
        this.func_two();
    }

Then it does trigger second function. But I want to trigger it this way this.func_one. IS it possible to do it this way? How?

Om3ga
  • 30,465
  • 43
  • 141
  • 221
  • 3
    I really don't get "I want to do it this way" at all. Calling a function is done by writing `()` after it. If you want to do it another way, you have to find another programming language that agrees with you. – Jon Apr 23 '13 at 08:45
  • There is a way in backbone for example `this.collection.each(this.render, this);`. this.render is a function which is called without brackets. – Om3ga Apr 23 '13 at 08:47
  • 2
    @x4ph4r: No, the function is not called in this case. You are just passing a reference to the function to `.each` and `.each` calls it internally. – Felix Kling Apr 23 '13 at 08:58
  • What do you want to achieve? – Alp Apr 23 '13 at 09:47
  • @Alp I was trying to solve http://stackoverflow.com/questions/16163934/clicking-on-child-element-also-triggers-click-event-on-it-parent in different way but now it is not possible to do it this way, I guess. – Om3ga Apr 23 '13 at 10:37

2 Answers2

1

You have to put () when you call a function, you can't just, out of nowhere, decide that you want it to work another way.

Take a look at this answer, it may help you.

Community
  • 1
  • 1
Padrus
  • 2,013
  • 1
  • 24
  • 37
0

this.func_two;

This statement return the function. It does not call the function.

To call the function you have to add () at the end.

or you have to do it like:

f2=this.func_two;
f2();

Airful
  • 312
  • 2
  • 12