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:
make
stuffclosure on callfoohave information want
foo("bar")property ofdo, , reference information instuffdoobject viathis, 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
Post a Comment