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?

5
  • 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. Commented Apr 23, 2013 at 8: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. Commented Apr 23, 2013 at 8: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. Commented Apr 23, 2013 at 8:58
  • What do you want to achieve? Commented Apr 23, 2013 at 9:47
  • @Alp I was trying to solve stackoverflow.com/questions/16163934/… in different way but now it is not possible to do it this way, I guess. Commented Apr 23, 2013 at 10:37

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

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();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.