Re: Re: [PROPOSAL] use keyword

2014-07-26 Thread Michaël Rouges
Ok, ok, it's a bit that I dreaded opening this topic but the idea of ​​a shared private channel between two foreign scopes seemed interesting enough to suggest, at least to discuss it. Thanks to all. :) Michaël Rouges - https://github.com/Lcfvs - @Lcfvs

[PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
Hi all, There is any plan around un functionnality like the use keyword, in PHP. Why something like that? Because, in JS, there is no way to inject some variables, without touch the this object known in a function. The lone possible way is with ownmade functions, in the same context, by : `var

Re: [PROPOSAL] use keyword

2014-07-25 Thread David Bruant
Hi, Le 25/07/2014 20:52, Michaël Rouges a écrit : Hi all, There is any plan around un functionnality like the use keyword, in PHP. Why something like that? Because, in JS, there is no way to inject some variables, without touch the this object known in a function. Can you give an example of

Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
I am not sure I understand your problem but AFAIK php introduced use to simulate JavaScript implicit outer scope access instead of the explicit global context php is (in)famous for, it comes quite as a surprise you are asking JS to simulate PHP here :-) `var test, fn; fn = new

Re: [PROPOSAL] use keyword

2014-07-25 Thread Tab Atkins Jr.
On Fri, Jul 25, 2014 at 11:52 AM, Michaël Rouges michael.rou...@gmail.com wrote: Hi all, There is any plan around un functionnality like the use keyword, in PHP. PHP's use() syntax is because PHP doesn't have actual lexical closures; it's a hack around the lack. Why something like that?

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
Hi David. Sure... I make a library that that needs to share a private variable with all methods of an instance passed by arguments on my lib' method. ``` var lib; (function () { var shared; shared = 'a shared value'; lib = { method: function method(foreignObject) {

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
function wrap(method) { return function () { var args = [].slice.call(arguments); args[0] = shared; return method.aply(this, args); }; } foreignObject[property] = wrap(foreignObject[property]); ? you still have the problem with the non writable methods ... but hey, that's

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@Andrea : Yeah, I don't really want to rewrite the methods, I only want to share my shared variable with these methods. Furthermore, your code don't works because method don't knows shared. Michaël Rouges - https://github.com/Lcfvs - @Lcfvs ___

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Tab Atkins Jr.
On Fri, Jul 25, 2014 at 12:56 PM, Michaël Rouges michael.rou...@gmail.com wrote: Hi David. Sure... I make a library that that needs to share a private variable with all methods of an instance passed by arguments on my lib' method. ``` var lib; (function () { var shared; shared

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 4:25 PM, Michaël Rouges michael.rou...@gmail.com wrote: @Andrea : Yeah, I don't really want to rewrite the methods, I only want to share my shared variable with these methods. Furthermore, your code don't works because method don't knows shared. You could

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
the method knows shared as soon as you define it inside your closure ... ``` var lib; (function () { var shared; shared = 'a shared value'; function wrap(method) { return function () { var args = [].slice.call(arguments); args[0] = shared; return

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
forgot to fix one of many typos in your initial example too ... `if (foreignObject.hasOwnProperty(property)) {` ... On Fri, Jul 25, 2014 at 1:33 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: the method knows shared as soon as you define it inside your closure ... ``` var lib;

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 4:29 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Fri, Jul 25, 2014 at 12:56 PM, Michaël Rouges michael.rou...@gmail.com wrote: Hi David. Sure... I make a library that that needs to share a private variable with all methods of an instance passed by

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ TJ, Rick : I'm really interested too! On an another side, my next idea, for the same goal, is a thing like : ```Function.prototype.attachContext()``` Where an attachContext call can share the context of the current scope with the related function. Michaël Rouges - https://github.com/Lcfvs

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 4:39 PM, Michaël Rouges michael.rou...@gmail.com wrote: @ TJ, Rick : I'm really interested too! On an another side, my next idea, for the same goal, is a thing like : ```Function.prototype.attachContext()``` Where an attachContext call can share the context of the

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Tab Atkins Jr.
On Fri, Jul 25, 2014 at 1:35 PM, Rick Waldron waldron.r...@gmail.com wrote: On Fri, Jul 25, 2014 at 4:29 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: Ah, so you've got a private variable (declared in a closure) that you want to share with other objects which aren't created in the same

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
Um, no, I was thinking something like : ``` var fn; fn = function fn() { // After the context is attached fn scope already knows shared }; (function () { var shared; shared = 'message'; fn.attachContext(); }());``` Michaël Rouges - https://github.com/Lcfvs - @Lcfvs

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
as a knonw convention in your code that would work but I have no idea what was anymore the first request at this point. Best Regards On Fri, Jul 25, 2014 at 1:53 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Fri, Jul 25, 2014 at 1:35 PM, Rick Waldron waldron.r...@gmail.com wrote: On

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
1. I don't understand what you are trying to do and why 2. I don't think any of this woul dhave been solved anyway with use , neither in PHP Hope others can help more. Best Regards On Fri, Jul 25, 2014 at 1:57 PM, Michaël Rouges michael.rou...@gmail.com wrote: Um, no, I was thinking

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 4:53 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: On Fri, Jul 25, 2014 at 1:35 PM, Rick Waldron waldron.r...@gmail.com wrote: On Fri, Jul 25, 2014 at 4:29 PM, Tab Atkins Jr. jackalm...@gmail.com wrote: Ah, so you've got a private variable (declared in a closure)

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ Andrea : The why comes from an another question : why to reserve the variables sharing (across the scopes) for the parenst/childs relations. Imho, some things should be shared with objects out of this of relationship type, no? :) Michaël Rouges - https://github.com/Lcfvs - @Lcfvs

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
let's do this way: you write down in some working PHP what you are trying to achieve and I'll give you back the equivalent JS, if possible ... otherwise I think I cannot help much here. Best Regards P.S. Rick ... lol, true that, but if you imagine those functions returned and used outside that

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@Andrea : There is no real equivalent in PHP. I only used the use keyword as example to suggest, in your mind, an ability to share vars with a foreign function without to touch the foreign function arguments. ;) Michaël Rouges - https://github.com/Lcfvs - @Lcfvs

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 5:13 PM, Michaël Rouges michael.rou...@gmail.com wrote: @Andrea : There is no real equivalent in PHP. I only used the use keyword as example to suggest, in your mind, an ability to share vars with a foreign function without to touch the foreign function arguments.

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Rick Waldron
On Fri, Jul 25, 2014 at 4:57 PM, Michaël Rouges michael.rou...@gmail.com wrote: Um, no, I was thinking something like : ``` var fn; fn = function fn() { // After the context is attached fn scope already knows shared }; (function () { var shared; shared = 'message';

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ Rick : I don't missed but thanks :) Your example works but not in an private channel between the 2 scopes. And on your next post, yeah, it's exactly that sharing the pointers... but in single way (A to B) or (B to A) And I think to an another Function.prototype method to prevent this effect,

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
that's the nonsense I am talking about. In php use is defined at function definition time, it's not something you can attach later on. In JS you can use .call and .apply passing any context to any different function, unless already bound to another context, so you have already way more power than

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ Andrea : .call, .apply and .bind change the this in the function, then it can't catch the goal and it doesn't work with non-writable methods again. It's why my detailled example ( http://esdiscuss.org/topic/proposal-use-keyword#content-4) is written with object methods (to etablish all

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Andrea Giammarchi
methods again. It's why my detailled example ( http://esdiscuss.org/topic/proposal-use-keyword#content-4) is written with object methods (to etablish all constraints). And don't worry... dont make a fixation on the PHP use, read the last Rick's post. ;) Michaël Rouges - https://github.com

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ Andrea : Thanks for the fixes, I tried but got Internal server error, on edit. The Tab's solution works but not on a secure channel between the closures. Michaël Rouges - https://github.com/Lcfvs - @Lcfvs ___ es-discuss mailing list

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Michaël Rouges
@ Rick : Or a more controlled solution might be to create a method able to only attach one pointer at a time. What do You think about it? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Re: [PROPOSAL] use keyword

2014-07-25 Thread Frankie Bagnardi
I see where this might be convenient, but the down sides are much larger, similar to `with`, `eval`, or arbitrary global variables. It essentially destroys the ability of compilers, tools, and people to statically analyze the code. I'm all for laziness in code (e.g. destructuring), but not when