Is it possible to dynamically generate an array of browser-defined method names? As opposed to user- or library-defined via a for..in on [Object/Array/ etc].prototype. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jon L. wrote:> Is it possible to dynamically generate an array of browser-defined > method names? > > As opposed to user- or library-defined via a for..in on [Object/Array/ > etc].prototype. >I don''t think there is an easy way except to iterate all the standard browser objects before any script loads. But why in the world would you need to programmatically identify browser vs. user methods? - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I''m just toying around with some ideas. Really, just to know if it''s possible. But, your response still begs the question: how do you iterate default methods? Assuming no user-defined prototype methods have been created: var methods = []; for (var property in Object.prototype) methods.push(property); // methods => []; Or, assuming: Object.prototype.dummy = function () { return this; }; var methods = []; for (var property in Object.prototype) methods.push(property); // methods => ["dummy"]; Am I focusing on the wrong object to iterate? - Jon L. On Mar 13, 10:29 am, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jon L. wrote: > > Is it possible to dynamically generate an array of browser-defined > > method names? > > > As opposed to user- or library-defined via a for..in on [Object/Array/ > > etc].prototype. > > I don''t think there is an easy way except to iterate all the standard > browser objects before any script loads. But why in the world would you > need to programmatically identify browser vs. user methods? > > - Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> for (var property in Object.prototype) methods.push(property);That will give you the *name* of each property in Object.prototype, and then push the name (not the method reference) on the methods array, if that''s what you''re trying to do. It may be worth checking that that property defines a method before doing that (as opposed to a data member), e.g. (off the top of my head, untested): if (typeof Object.prototype[property] == "function") Provided you do this with inline code in the first script on the page, it should give you only the browser-defined ones, not ones added by other scripts. I think the "why" question still applies... ;-) FWIW, -- T.J. Crowder tj / crowder software / com On Mar 13, 7:36 pm, "Jon L." <jonllm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m just toying around with some ideas. > Really, just to know if it''s possible. > > But, your response still begs the question: how do you iterate default > methods? > > Assuming no user-defined prototype methods have been created: > var methods = []; > for (var property in Object.prototype) methods.push(property); > // methods => []; > > Or, assuming: > Object.prototype.dummy = function () { return this; }; > var methods = []; > for (var property in Object.prototype) methods.push(property); > // methods => ["dummy"]; > > Am I focusing on the wrong object to iterate? > > - Jon L. > > On Mar 13, 10:29 am, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Jon L. wrote: > > > Is it possible to dynamically generate an array of browser-defined > > > method names? > > > > As opposed to user- or library-defined via a for..in on [Object/Array/ > > > etc].prototype. > > > I don''t think there is an easy way except to iterate all the standard > > browser objects before any script loads. But why in the world would you > > need to programmatically identify browser vs. user methods? > > > - Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Jon L. wrote:> I''m just toying around with some ideas. > Really, just to know if it''s possible. > > > But, your response still begs the question: how do you iterate default > methods? > > Assuming no user-defined prototype methods have been created: > var methods = []; > for (var property in Object.prototype) methods.push(property); > // methods => []; > > Or, assuming: > Object.prototype.dummy = function () { return this; }; > var methods = []; > for (var property in Object.prototype) methods.push(property); > // methods => ["dummy"]; > > > Am I focusing on the wrong object to iterate? > > - Jon L.Yes, native instance methods are indeed hidden (are all static methods exposed?). Native instance methods should not be in the prototype property: the whole idea of prototyping is that prototype methods are /in addition to/ native instance methods. The only other thing I can think of is to test against a list of possible method names on an empty object. var possible = ''push pop slice bork''.split('' ''); var empty = []; var methods = []; for (var i = 0, length = possible.length; i < length; i++) if (typeof empty[possible[i]] == ''function'') methods.push(possible[i]); // methods = [''push'',''pop'',''slice'']; - Ken Snyder --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
@T.J. Crowder> and then push the name (not the method reference) on the methods > array, ...Sorry, I guess I didn''t clarify. All I''m actually wanting is the names. Which, I guess, I should''ve said "a list of native keys."> Provided you do this with inline code in the first script on the page,You can use Object#propertyIsEnumerable between the for...in and Array#push. true => indexes (in this case, user-created properties/methods) @Ken Snyder> The only other thing I can think of is to test against a list of > possible method names on an empty object.> the whole idea of prototyping is that prototype methods are > /in addition to/ native instance methods.Only adding to the possibility that the "dynamic" idea is hosed. ;) Note: You can still compare the list against a prototype object. They''re still part of it; just, apparently, not enumerable. @[all] Thanks for the help and input. - Jon L. On Mar 13, 5:34 pm, Ken Snyder <kendsny...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Jon L. wrote: > > I''m just toying around with some ideas. > > Really, just to know if it''s possible. > > > But, your response still begs the question: how do you iterate default > > methods? > > > Assuming no user-defined prototype methods have been created: > > var methods = []; > > for (var property in Object.prototype) methods.push(property); > > // methods => []; > > > Or, assuming: > > Object.prototype.dummy = function () { return this; }; > > var methods = []; > > for (var property in Object.prototype) methods.push(property); > > // methods => ["dummy"]; > > > Am I focusing on the wrong object to iterate? > > > - Jon L. > > Yes, native instance methods are indeed hidden (are all static methods > exposed?). Native instance methods should not be in the prototype > property: the whole idea of prototyping is that prototype methods are > /in addition to/ native instance methods. > > The only other thing I can think of is to test against a list of > possible method names on an empty object. > > var possible = ''push pop slice bork''.split('' ''); > var empty = []; > var methods = []; > for (var i = 0, length = possible.length; i < length; i++) > if (typeof empty[possible[i]] == ''function'') > methods.push(possible[i]); > // methods = [''push'',''pop'',''slice'']; > > - Ken Snyder--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Mar 13, 7:14 am, "Jon L." <jonllm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Is it possible to dynamically generate an array of browser-defined > method names?If by browser-defined you mean host objects, and if you want it to be reliable across browsers, then no as you don''t know if they are enumerable or not. There is no requirement for hosts to make them enumerable, although they seem to be in some browsers at least.> As opposed to user- or library-defined via a for..in on [Object/Array/ > etc].prototype.You can''t use for..in for built-in object properties as most are not enumerable. You can''t ignore native user-defined properties as they must be enumerable. All you can do it try to detect if they are on the object itself or somewhere on the prototype chain. Further, even for those properties that are enumerable, you don''t know all the possible objects that you need to iterate over, or if they exist to be iterable. How would you discover the HTMLTable.insertRow method unless you knew to build a table object first? -- Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---