[Proto-Scripty] Re: Custom signal
Hi, You suggested to use: a = [] instead of: a = new Array() What is the difference? It's shorter and does exactly the same thing. Similarly, `{}` is the same as `new Object()`. -- T.J. :-) On Dec 7, 9:43 pm, Frédéric f...@gbiloba.org wrote: On lundi 07 décembre 2009, Tobie Langel wrote: A couple suggestions: https://gist.github.com/bb3d40f6915118da4dec Thanks! You suggested to use: a = [] instead of: a = new Array() What is the difference? PS: about the try/catch, in my real code, I log the error on Firebug console... -- Frédéric -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Custom signal
I'm not sure it will do what I'm looking for. If I understand, your code will call the same func with all arguments, but one by one. What I want to do is to call each slot with all arguments. Here is an example: function func1(arg1, arg2) { ... } function func2(arg1, arg2) { ... } mySignal = new Signal(); mySignal.connect(func1); mySignal.connect(func2); The call: mySignal.emit('a', 3); will in fact do: func1('a', 3); func2('a', 3); -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Custom signal
the global variable arguments will give u an array of arguments... https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/arguments Alex Mcauley http://www.thevacancymarket.com - Original Message - From: fma f...@gbiloba.org To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, December 07, 2009 9:31 AM Subject: [Proto-Scripty] Re: Custom signal I'm not sure it will do what I'm looking for. If I understand, your code will call the same func with all arguments, but one by one. What I want to do is to call each slot with all arguments. Here is an example: function func1(arg1, arg2) { ... } function func2(arg1, arg2) { ... } mySignal = new Signal(); mySignal.connect(func1); mySignal.connect(func2); The call: mySignal.emit('a', 3); will in fact do: func1('a', 3); func2('a', 3); -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Custom signal
Good! Is it possible to pass again this var to another function? What if I do: function func2(arguments) { ... } function func1() { func2(arguments); } func1(a, b); Does it work? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Custom signal
Hi fma, If you test exemple you'll gave, it could result in something like that: function func2(arguments) { alert(arguments); alert($A(arguments)); } function func1() { func2(arguments); } func1('a1','b2'); The body of func2 will alert the arguments received, which ius of course the one you create in the call to func1. in first alert, you'll receive the native arguments. It is in fact not a real object, but a fake Array. It means, that it's an array with only some Array's methods (like length). But thanks to prototype, you could convert it in a REAL array with standard method, and prototype method. An now it's a pleasure playing with arguments :)) -- david On 7 déc, 12:53, fma f...@gbiloba.org wrote: Good! Is it possible to pass again this var to another function? What if I do: function func2(arguments) { ... } function func1() { func2(arguments); } func1(a, b); Does it work? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Custom signal
arguments is global... consider this ... function foo('one','two','three') { alert(arguments[0]); // one alert(arguments[1]); // two alert(arguments[2]); // three } Alex Mcauley http://www.thevacancymarket.com - Original Message - From: fma f...@gbiloba.org To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, December 07, 2009 11:53 AM Subject: [Proto-Scripty] Re: Custom signal Good! Is it possible to pass again this var to another function? What if I do: function func2(arguments) { ... } function func1() { func2(arguments); } func1(a, b); Does it work? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
[Proto-Scripty] Re: Custom signal
@fma: Is it possible to pass again this var to another function? What if I do: Worth reading up on the `arguments` variable in the spec[1] (warning, multi-meg PDF). Also check out Function#apply, which is probably what you're looking for: var Thingy = Class.create((function(){ function foo() { bar.apply(this, arguments); } function bar(a, b, c) { alert(a = + a); alert(b = + b); alert(c = + c); } return {foo: foo, bar: bar}; })()); var t = new Thingy(); t.foo(1, 2, 3); // Alerts a = 1, then b = 2, then c = 3 The first argument to Function#apply is the context (the value `this` should have within the call). The second argument is an array (or array-like thing, such as `arguments`) of arguments to pass to the function. [1] http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf @Alex: arguments is global... No, it's local to the function scope, like the formal arguments and vars inside the function (in fact, like them it's a property of the variable object for that execution context). -- T.J. Crowder Independent Software Consultant tj / crowder software / com www.crowdersoftware.com On Dec 7, 12:26 pm, Alex McAuley webmas...@thecarmarketplace.com wrote: arguments is global... consider this ... function foo('one','two','three') { alert(arguments[0]); // one alert(arguments[1]); // two alert(arguments[2]); // three } Alex Mcauleyhttp://www.thevacancymarket.com - Original Message - From: fma f...@gbiloba.org To: Prototype script.aculo.us prototype-scriptaculous@googlegroups.com Sent: Monday, December 07, 2009 11:53 AM Subject: [Proto-Scripty] Re: Custom signal Good! Is it possible to pass again this var to another function? What if I do: function func2(arguments) { ... } function func1() { func2(arguments); } func1(a, b); Does it work? -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en. -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Custom signal
Le lundi 7 décembre 2009 12:46, T.J. Crowder a écrit : Worth reading up on the `arguments` variable in the spec[1] (warning, multi-meg PDF). Also check out Function#apply, which is probably what you're looking for: It works fine! Here is the code I now use: var Signal = Class.create({ initialize: function () { this._slots = new Array(); }, emit: function() { for (i = 0; i this._slots.length; i++) { try { this._slots[i].apply(this, arguments); } catch (e) { } } }, connect: function(slot) { if (!this._slots.include(slot)) { this._slots.push(slot); } }, disconnect: function(slot) { if (this._slots.include(slot)) { this._slots.splice(this._slots.indexOf(slot, 1)); } }, disconnectAll: function() { this._slots = new Array(); }, }); Thanks for your help :o) -- Frédéric -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
Re: [Proto-Scripty] Re: Custom signal
On lundi 07 décembre 2009, Tobie Langel wrote: A couple suggestions: https://gist.github.com/bb3d40f6915118da4dec Thanks! You suggested to use: a = [] instead of: a = new Array() What is the difference? PS: about the try/catch, in my real code, I log the error on Firebug console... -- Frédéric -- You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptacul...@googlegroups.com. To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.