[Proto-Scripty] Re: $$ failing in FF3.1b3
On 10 Mar, 07:25, Jim Higson j...@wikizzle.org wrote: On Monday 09 March 2009 21:51:05 kangax wrote: It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. Makes sense. if( !hasOwnProperty ) hasOwnProperty = function hasOwnProperty(){ ... }; I was thinking of something like: var hasOwnProperty = (function(){ var hop = Object.prototype.hasOwnProperty; if (hop) { return function(obj, prop) { return hop.call(obj, prop); } } Why not: if( hop ) return hop; Does hop need to be wrapped? Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why not just encapsulate the `call`? return function(obj, prop) { if (obj) { var c = obj.constructor; if (c c.prototype) { return obj[prop] !== c.prototype[prop]; } } return null; } })(); This fallback not bullet-proof, but should cover most of the cases. Yep, the tragic case where something just happens to have a property in a prototype *and* the same property directly - could happen! Still, I think the code above would be fine for almost all cases. Another edge case is when an object does not expose (think host objects in MSHTML DOM) or is missing `constructor` altogether (e.g. if it was overwritten). I remember seeing solutions involving deleting object's `__proto__` (if supported), checking property with `in` and then restoring `__proto__` back. Relying on such manipulations is like playing with fire, of course : ) It is probably also slower. -- kangax --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Tuesday 10 March 2009 14:06:17 kangax wrote: It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. Makes sense. if( !hasOwnProperty ) hasOwnProperty = function hasOwnProperty(){ ... }; I was thinking of something like: var hasOwnProperty = (function(){ var hop = Object.prototype.hasOwnProperty; if (hop) { return function(obj, prop) { return hop.call(obj, prop); } } Why not: if( hop ) return hop; Does hop need to be wrapped? Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why not just encapsulate the `call`? Ah, yes, I imagined we'd be adding hasOwnProperty to Object.prototype to make the bad browsers like the good. Given the subject, probably not wise :-) return function(obj, prop) { if (obj) { var c = obj.constructor; if (c c.prototype) { return obj[prop] !== c.prototype[prop]; } } return null; } })(); This fallback not bullet-proof, but should cover most of the cases. Yep, the tragic case where something just happens to have a property in a prototype *and* the same property directly - could happen! Still, I think the code above would be fine for almost all cases. Another edge case is when an object does not expose (think host objects in MSHTML DOM) or is missing `constructor` altogether (e.g. if it was overwritten). I remember seeing solutions involving deleting object's `__proto__` (if supported), checking property with `in` and then restoring `__proto__` back. Relying on such manipulations is like playing with fire, of course : ) It is probably also slower. Yep, sounds dangerous! -- Jim my wiki ajaxification thing: http://wikizzle.org my blog: http://jimhigson.blogspot.com/ --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Mar 10, 11:30 am, Jim Higson j...@wikizzle.org wrote: On Tuesday 10 March 2009 14:06:17 kangax wrote: [...] Writing `hasOwnProperty.call(object, property)` is a bit tedious. Why not just encapsulate the `call`? Ah, yes, I imagined we'd be adding hasOwnProperty to Object.prototype to make the bad browsers like the good. Given the subject, probably not wise :-) We thought about it too, of course. I actually don't mind extending native prototypes if it is done to fix broken behavior. Unfortunately, in Safari 2 adding `hasOwnProperty` to `Object.prototype` would *not* give it a DontEnum flag and so it would be iterated over with for/in. Oh well : ) [...] -- kangax --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Mar 9, 6:57 am, Jim Higson j...@wikizzle.org wrote: On Friday 06 March 2009 15:26:49 kangax wrote: [...] It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. Makes sense. if( !hasOwnProperty ) hasOwnProperty = function hasOwnProperty(){ ... }; I was thinking of something like: var hasOwnProperty = (function(){ var hop = Object.prototype.hasOwnProperty; if (hop) { return function(obj, prop) { return hop.call(obj, prop); } } return function(obj, prop) { if (obj) { var c = obj.constructor; if (c c.prototype) { return obj[prop] !== c.prototype[prop]; } } return null; } })(); This fallback not bullet-proof, but should cover most of the cases. [...] -- kangax --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Thursday 05 March 2009 23:22:26 Tobie Langel wrote: Hi, Extending Object.prototype is regarded as a Bad Thing[1]. Does Prototype state anywhere that it doesn't work if Object.prototype is extended? If this is a stated limitation then fair enough I guess. It seems like some parts of Prototype are designed to work with code that adds to Object.Prototype, for example in the Hash class we have: get: function(key) { // simulating poorly supported hasOwnProperty if (this._object[key] !== Object.prototype[key]) return this._object[key]; }, The main reason being that cross-browser support for hasOwnProperty is fairly recent (Safari 2 doesn't have it for example). I didn't know that, thanks for the info. What happens if you use hasOwnProperty in Safari 2? I don't have any usage statistics but I'd guess Safari 2 isn't used much now. According to Wikipedia the last version was 2.0.4, released 13th January 2006 and was replaced with 3.0.0 on the 11th June 2007. [1] http://erik.eae.net/archives/2005/06/06/22.13.54/ On Mar 5, 6:34 pm, Jim Higson j...@wikizzle.org wrote: On Thursday 05 March 2009 16:16:05 Jim Higson wrote: Hi, Is anybody else finding this? Does Prototype from git work with FF3.1? On closer inspection, it is quite easy to get Prototype to throw similar errors even in FF3. It just happens that my present code only provokes it in 3.1. For example here:http://users.ox.ac.uk/~admn2094/test.html Basically, writeAttribute tries to add an attribute called 'foo' somewhere with the value function foo(){ return @@ } and this fails because of the illegal @ char. Are you not allowed to extend Object when using prototype? Prototype doesn't seem to do any hasOwnProperty checks: http://yuiblog.com/blog/2006/09/26/for-in-intrigue/ File as a bug? -- Jim my wiki ajaxification thing:http://wikizzle.org my blog:http://jimhigson.blogspot.com/ -- Jim my wiki ajaxification thing: http://wikizzle.org my blog: http://jimhigson.blogspot.com/ --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Mar 6, 5:49 am, Jim Higson j...@wikizzle.org wrote: On Thursday 05 March 2009 23:22:26 Tobie Langel wrote: Hi, Extending Object.prototype is regarded as a Bad Thing[1]. Does Prototype state anywhere that it doesn't work if Object.prototype is extended? If this is a stated limitation then fair enough I guess. I think not, but probably should. Mind creating a ticket? It seems like some parts of Prototype are designed to work with code that adds to Object.Prototype, for example in the Hash class we have: get: function(key) { // simulating poorly supported hasOwnProperty if (this._object[key] !== Object.prototype[key]) return this._object[key]; }, Not exactly. The fact that it works with augmented `Object.prototype` is only a consequence of another workaround :) The check is there to return only user-defined keys; Even without `Object.prototype` modification, you would get unexpected result when querying for, say, `toString` on a new Hash instance: $H({ foo: 1, bar: 2 }).get('toString'); It's possible that we'll introduce a custom `hasOwnProperty` in later revisions. The main reason being that cross-browser support for hasOwnProperty is fairly recent (Safari 2 doesn't have it for example). I didn't know that, thanks for the info. What happens if you use hasOwnProperty in Safari 2? Use as in try to call it? IIRC, you get hasOwnProperty is not a function error. In other words, it simply doesn't exist : ) I don't have any usage statistics but I'd guess Safari 2 isn't used much now. According to Wikipedia the last version was 2.0.4, released 13th January 2006 and was replaced with 3.0.0 on the 11th June 2007. Yeah, Safari 2 is pretty close to being out. [...] -- kangax --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
On Thursday 05 March 2009 16:16:05 Jim Higson wrote: Hi, Is anybody else finding this? Does Prototype from git work with FF3.1? On closer inspection, it is quite easy to get Prototype to throw similar errors even in FF3. It just happens that my present code only provokes it in 3.1. For example here: http://users.ox.ac.uk/~admn2094/test.html Basically, writeAttribute tries to add an attribute called 'foo' somewhere with the value function foo(){ return @@ } and this fails because of the illegal @ char. Are you not allowed to extend Object when using prototype? Prototype doesn't seem to do any hasOwnProperty checks: http://yuiblog.com/blog/2006/09/26/for-in-intrigue/ File as a bug? -- Jim my wiki ajaxification thing: http://wikizzle.org my blog: http://jimhigson.blogspot.com/ --~--~-~--~~~---~--~~ 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-scriptaculous@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: $$ failing in FF3.1b3
Hi, Extending Object.prototype is regarded as a Bad Thing[1]. The main reason being that cross-browser support for hasOwnProperty is fairly recent (Safari 2 doesn't have it for example). Best, Tobie [1] http://erik.eae.net/archives/2005/06/06/22.13.54/ On Mar 5, 6:34 pm, Jim Higson j...@wikizzle.org wrote: On Thursday 05 March 2009 16:16:05 Jim Higson wrote: Hi, Is anybody else finding this? Does Prototype from git work with FF3.1? On closer inspection, it is quite easy to get Prototype to throw similar errors even in FF3. It just happens that my present code only provokes it in 3.1. For example here:http://users.ox.ac.uk/~admn2094/test.html Basically, writeAttribute tries to add an attribute called 'foo' somewhere with the value function foo(){ return @@ } and this fails because of the illegal @ char. Are you not allowed to extend Object when using prototype? Prototype doesn't seem to do any hasOwnProperty checks: http://yuiblog.com/blog/2006/09/26/for-in-intrigue/ File as a bug? -- Jim my wiki ajaxification thing:http://wikizzle.org my blog:http://jimhigson.blogspot.com/ --~--~-~--~~~---~--~~ 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-scriptaculous@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 -~--~~~~--~~--~--~---