insteadof operator

Bucaran jbucaran at me.com
Thu Jun 25 23:17:52 UTC 2015


The default behavior is best most of the time, but for those times when you need the object in the parent scope I thought it’d nice :)

> What would happen if this operator was used in the global scope?

It should throw an runtime error.

> On Jun 26, 2015, at 7:58 AM, Edwin Reynoso <eorroe at gmail.com> wrote:
> 
> I'm highly doubting something like this will be made just because of wanting to use the same variable name. What's the real use, besides more code than using a different variable name.
> 
> On Thu, Jun 25, 2015 at 6:46 PM, Jordan Harband <ljharb at gmail.com <mailto:ljharb at gmail.com>> wrote:
> What would happen if this operator was used in the global scope?
> 
> On Thu, Jun 25, 2015 at 3:41 PM, Bucaran <jbucaran at me.com <mailto:jbucaran at me.com>> wrote:
> Sometimes you have a function that receives a parameter shadowing an existing function or variable in the parent scope.
> 
> In _some_ cases I would like to use the same variable name to avoid having to come up with new names. Contrived example ahead:
> 
> ```js
> import path from "path"
> 
> function doSomething (_path) {
>         if (path.dirname(_path) === "/" ) {
>         // ...
>         } else {
>         }
> }
> ```
> 
> It would be nice if there was a special construct like `typeof` or `instanceof` that would take a name and evaluate to whatever
> variable / function of the same name existing in the parent scope (or undefined otherwise).
> 
> ```js
> import path from "path"
> 
> function doSomething (path) {
>         if ((insteadof path).dirname(path) === "/" ) {
>         // ...
>         } else {
>         }
> }
> ```
> 
> In this case the expression above using the made-up `inteadof` operator would evaluate to the imported `path` variable
> instead of the `path` variable name.
> 
> 
> Regards
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss>
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150626/c613624f/attachment.html>


More information about the es-discuss mailing list