[Prototype-core] Re: $ function
On Jun 21, 6:30 am, Rebecca Blyth [EMAIL PROTECTED] wrote: Finally, an aside on not having control over the HTML source: I ran into this issue when using the radio_button_tag helper method in Rails, which inconveniently used the name of the input as the id - unhelpful, as all the radio buttons in a group have the same name in order to group them. That's somewhat brain-dead behavior on the part of Rails. I'd encourage you to file a bug report on the ActionView component. Cheers, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
On Jun 21, 2:35 pm, sed [EMAIL PROTECTED] wrote: I'm not sure why this worked before, it must be related to the html/ script being generated into the div from the ajax.updater rather than just being on the page. Nope. It's sillier than that. Let's say you've got an element with an ID of foo on the page: var f = new String(foo); $(f); //- null document.getElementById('foo') //- [object HTMLElement] This can be traced to JavaScript's bizarre String constructor -- `typeof f` returns object, not string. Looking at `f` in Firebug will reveal ['f', 'o', 'o']. This is a crack in the object/primitive duality of types like String and Number. The $ function uses the typeof operator to figure out if the passed argument is a string. Since it doesn't appear to be one, it doesn't get run through document.getElementById. You've found the solution already -- the new String call is superfluous. Cheers, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
Hi guys. I'm new in prototypejs and script.aculo. But, lets consider Andrew Dupont's example again: var f = new String(foo); alert($(f)) //- foo alert(document.getElementById('foo')) //- [object HTMLElement] It has cause: When String( ) is used as a constructor with the new operator, it returns a String object, which holds the string s or the string representation of s. When the String( ) constructor is used without the new operator, it simply converts s to a primitive string and returns the converted value. it's mean: alert(typeof new String()) //- object alert(typeof String()) //- string Possible, it will be better to redefine $ like this: function $(element) { if (arguments.length 1) { for (var i = 0, elements = [], length = arguments.length; i length; i++) elements.push($(arguments[i])); return elements; } if (typeof element == 'string' || element instanceof String) //- NEW CONDITION element = document.getElementById(element); return Element.extend(element); } Or it isn't good idea. What do you think? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
On 6/22/07, Tobie Langel [EMAIL PROTECTED] wrote: The String function/constructor is maybe useful for other things [...] Like what exactly !? Like when casting something to string when toString is not sufficient. I don't know when that may be. I was just stating this: although this may be a feature of the JS language that has real-world usage, I sincerely doubt that its usage applies to short, simple strings that are element IDs. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
I don't see the harm in adding the second condition element instanceof String you could use : if(element element.constructor == String) This works for both foo and new String(foo); I find that it is faster than using typeOf. I have made very JavaScript heavy applications and noticed that using typeOf value == 'Object' and others is slow compared to myObject.constructor, especially when called a few thousand times. Also I don't buy the it hasn't been fixed since the beginning, so why fix it now? argument. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
On 6/22/07, Tobie Langel [EMAIL PROTECTED] wrote: I'm actually getting faster results in Firefox for typeof in that particular case. Me too. Try it for yourself: http://gfx.neohub.com/benchmark/creator.html --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
If you run it more than once you get different results. Reguardless of this benchmark (I got it to show .constructor was faster consistently more times, IE) Its a method of detecting a string that will fix the issue. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: bracket notation
And using : http://gfx.neohub.com/benchmark/creator.html Firefox: slower by alot using constructor IE : faster by alot using constructor return ('hi'.constructor == String); vs return (typeof 'hi' == 'string'); IE: faster by alot using constructor Firefox : mixed (sometimes slower sometimes faster) return ({}.constructor == Object); vs return (typeof {} == 'object'); I have tried both in my applications and dont notice a speed decrease in firefox (using firebug) that is notable. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Small Documentation Request - Enumerable.invoke
Hi Team, I just wanted to make a small documentation request for Enumerable.invoke. I discovered it useful that invoke returns the processed array of items. The docs specify that invoke returns an array, but it isn't clear that you can chain two invoke commands to call two methods in succession. See examples below. Thanks, Ken Snyder $$('div.thumbnail') .invoke('observe','mouseover',thumbMouseOver) .invoke('observe','mouseout',thumbMouseOut); $$('#windows div.close') .invoke('addClassName','active') .invoke('show'); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Small Documentation Request - Enumerable.invoke
Thanks. It's not obvious to all, so I added one of your examples to the doc. On 6/22/07, Ken Snyder [EMAIL PROTECTED] wrote: Hi Team, I just wanted to make a small documentation request for Enumerable.invoke. I discovered it useful that invoke returns the processed array of items. The docs specify that invoke returns an array, but it isn't clear that you can chain two invoke commands to call two methods in succession. See examples below. Thanks, Ken Snyder $$('div.thumbnail') .invoke('observe','mouseover',thumbMouseOver) .invoke('observe','mouseout',thumbMouseOut); $$('#windows div.close') .invoke('addClassName','active') .invoke('show'); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Small Documentation Request - Enumerable.invoke
Mislav Marohnić wrote: Thanks. It's not obvious to all, so I added one of your examples to the doc. Awesome! That was faster than approving a wiki edit :P --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---