Hi. I have never written a proposal before, but I would love if it was possible to do the following in JavaScript:
```js // This code exposes a function that when called bound to an `object` inserts a method in that `object`. // The following are 3 ways to do this, the last one being my proposal. Note that I am using CommonJS // require style to include modules, but that is simply to illustrate how I came up with thi. Using `export default function…` // does not really address my use case, but just for completeness I have included an example using the new `import` // `export` system as well. // Disclaimer: This is a simple plugin-like system example, but notice I am not checking whether the // method already exist in `object`. You can ignore this. // Idiomatic JavaScript module.exports = function () { let method = require("./lib/method") this.method = function (…args) { return args.map((arg) => method(arg)) } } // Clumsy, but without using `let` variables module.exports = function () { this.method = function (…args) { return (function (method) { return args.map((arg) => method(path)) }( require(“./lib/method") )) } } // My proposal is to allow blocks to receive arguments (similar to the non-standard let blocks) and // whatever you return inside the block is the return value of the enclosing function. Also, there // should be no need to write `return` as it will always return the result of the last expression. module.exports = function () { this.method = function (…args) { (method) { args.map((arg) => method(arg)) }(require("./lib/method") } } // Just for completeness, but not really related to what I am proposing (although it does solve this particular case very neatly) using import & exports import method from "./method" exports default function () { this.method = function (…args) { return args.map((arg) => method(arg)) } } ``` If you think this is a good or bad idea, please let me know your comments and observations. Regards J > On Jun 20, 2015, at 8:07 PM, Benjamin Gruenbaum <benjami...@gmail.com> wrote: > > As a cross-cutting concern I'd like the feedback of more people on > https://github.com/benjamingr/RegExp.escape/issues/29 > <https://github.com/benjamingr/RegExp.escape/issues/29> > > Basically we've got to make a design choice of readable output vs. > potentially safer output. > > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss