0

I would need to declare Methods within Methods and call them outside as a Object, Method connotation... To make it more clear:

I need to call:

Object.Method().nestedMethod();

how can I do it so? This failed so far:

function Object(){ 
     this.Method = function(){

          this.Method.nestedMethod = function(){

          };

     };

}

As I work on a DSL it is necessary to call a Method within a Method. In this case the last Method is some kind of recursion Method of the previous one, like this:

Object.execute(param).recursion();

How would I have to declare the nested Method to access this so?

2
  • Why exactly ? What's the real purpose ? Do you want, in fact, chaining ? Commented Jul 22, 2014 at 16:03
  • Yes, I writing some kind of DSL, and need to chain the Methods... And, I'm also giving parameters, so when calling Object.Method(param).nestedMethod(); - nestedMethod needs to know "param"... Commented Jul 22, 2014 at 16:13

1 Answer 1

1

You can return an object that contains nestedMethod:

Object.Method = function () {
    return {
        nestedMethod: function () {}
    };
}
Sign up to request clarification or add additional context in comments.

4 Comments

A new Object would be needed to call that (with a different name than "Object", hopefully)
Don't works really for me... Can you go more in detail?
@DamianT.Dziwis What does it return for you when you call Object.Method().nestedMethod();?
It returns nothing, I need to write a recursion function... Maybe this makes it more clear: Procedure.execute(param).loop(cycles); - so loop will call execute(param) in cycle times... Its necessary to do it nested...

Your Answer

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