Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript - What is the best method when creating chainable functions?
    primarykey
    data
    text
    <p><strong>EDIT</strong> <br> Here is an attempt to make my question simpler.</p> <pre><code>return this.someFunc(); == return { XXX:this.someFunc() }; </code></pre> <p><strong>What do I have to put in for XXX to make this statement true?</strong> <hr> I'm trying to create a function that can be chained. Let me write some hypothetical code. (Any syntax errors just ignore, I'm typing this fast and this is just concept code.) Assume that all functions are either defined locally or globally. :)</p> <pre><code>test = function(){ this.someFunc = function(){ this.retest = function(){ //...code } //...code } this.someFunc2 = function(){ //...code } return this.someFunc(); } </code></pre> <p>This function allows me to chain: <code>test().retest();</code> <br> But what I want to do is return more than one item.</p> <pre><code>test = function(){ this.someFunc = function(){ this.retest = function(){ //...code } //...code } this.someFunc2 = function(){ //...code } return { XXX:this.someFunc(), //What do I put for XXX next:this }; } </code></pre> <p>I want to do this to access another function that test() offers: <code>test().next.someFunc2();</code> <br></p> <p><strong>So my problem is this:</strong> <br> I still want to be able to chain like this: <code>test().retest();</code> <br> But I have to do it like this: <code>test().XXX.retest();</code> <br><br> In my code, what is the name that I can put instead of XXX to accomplish this? And is this even possible? I have tried <code>0</code> and <code>default</code> already. Thanks for the help.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload