javascript - method chaining with sub-methods -


i trying use method chain sub-methods.

ie: foo("bar").do.stuff()

the catch stuff() needs have reference value of bar("bar")

is there this.callee or other such reference achieve this?

is there this.callee or other such reference achieve this?

no, you'd have have foo return object do property on it, either:

  1. make stuff closure on call foo

  2. have information want foo("bar") property of do, , reference information in stuff do object via this, or

// closure example:  function foo1(arg) {    return {      do: {        stuff: function() {          snippet.log("the argument foo1 was: " + arg);        }      }    };  }  foo1("bar").do.stuff();    // using `do` object example (the `do` constructor , prototype  // highlight `stuff` need not closure):  function do(arg) {    this.arg = arg;  }  do.prototype.stuff = function() {    snippet.log("the argument foo2 was: " + this.arg);  };  function foo2(arg) {    return {      do: new do(arg)    };  }  foo2("bar").do.stuff();
<!-- script provides `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->  <script src="//tjcrowder.github.io/simple-snippets-console/snippet.js"></script>


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -