Re: libseed-list Fwd: [Bug 610317] New: Provide a builtin dir() function




Yeah, had a chat with my Python guy here, - Object.keys() is probably the more Javascriptey way of implementing it..

Object.keys =  function(o, fn, scope){
         var ret = [];
         for(var p in o){
            if (typeof(p) != 'number') ret.push(k);;
         }
	  return ret;
};



Tim Horton wrote:
The name and very specific scope/usage are classic Python, for what it's worth. And I've actually gotten a bunch of emails asking why Seed doesn't have something similar...

On Feb 17, 2010, at 21:15, Alan Knowles wrote:

Apart from the rather awful name (When I first saw it, I expected it to scan directories) - A more generic function may be better..

Note: - this does not mess with prototypes, which can cause real nightmares..

Object.filter =  function(o, fn, scope){
          var ret = [];
          for(var p in o){
              if(fn.call(scope , o[p], p, o, ret) === false){ return ret; };
          }
	    return ret;
      };

Object.filter(obj, 		function(v, k, o, ret) {
			 if (typeof(k) != 'number') ret.push(k);
		 }
     ).join(' ,');



It made me wonder how much of the JS 1.6 iterator support is available in webkit.. - never really looked at it, as it's been so mozilla specific before..
https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array

Regards
Alan


Tim Horton wrote:
Do people think this belongs on the Seed object (Seed.dir()) or should it be global? We were trying not to clutter up the global namespace, but making it global would probably make it more obvious for people coming from elsewhere.

Begin forwarded message:

*From: *"seed" (bugzilla.gnome.org <http://bugzilla.gnome.org>) <bugzilla gnome org <mailto:bugzilla gnome org>>
*Date: *February 17, 2010 17:11:02 EST
*To: *hortont424 gmail com <mailto:hortont424 gmail com>
*Subject: **[Bug 610317] New: Provide a builtin dir() function*

https://bugzilla.gnome.org/show_bug.cgi?id=610317
seed | libseed | git head

         Summary: Provide a builtin dir() function
  Classification: Other
         Product: seed
         Version: git head
      OS/Version: Linux
          Status: UNCONFIRMED
        Severity: normal
        Priority: Normal
       Component: libseed
      AssignedTo: seed-maint gnome bugs
      ReportedBy: diegoe gnome org
    GNOME target: ---
   GNOME version: ---


Just like in Python, this is doable in Javascript easily:

function dir(object)
{
  methods = [];
  for (z in object) if (typeof(z) != 'number') methods.push(z);
  return methods.join(', ');
}

--
Configure bugmail: https://bugzilla.gnome.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching the assignee of the bug.
------------------------------------------------------------------------

_______________________________________________
libseed-list mailing list
libseed-list gnome org
http://mail.gnome.org/mailman/listinfo/libseed-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]