Michael Peters wrote:
> ...
> Just some random thoughts: maybe putting it in String since it returns a 
> string?
> String.createUid()? Or maybe hanging it off of Prototype itself (seems like 
> that
> would set a bad precedent for hanging tons of useful methods off of the
> Prototype namespace). In Perl land we have Data::UUID for stuff like this, so
> maybe we should introduce a Data namespace?
>   
Having a general object utility is a good idea. And, as Ryan points out, 
a prefix can provide a simple convention for future access to elements 
without caching the ids.

Brainstorming in specifics, what about a method called 
Object#assignGuid?  After all, we are reading/writing a property of an 
object.  Below is Jeff's original function reincarnated.  I think it is 
simple and widely useful.

Object.assignGuid = function(object, prefix) {
  if (prefix === undefined) prefix = '__guid';
  if (!object.id) {
    object.id = prefix + (arguments.callee.nextId++);
  }
  return object.id;
};
Object.assignGuid.nextId = 0;


Then, if we wanted to cater to the high-use-case Element or 
Element.Method scenario:

Element.assignGuid = function(element, prefix) {
  return Object.assignGuid($(element), prefix);
};


- Ken Snyder


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to