Loading ...
Sorry, an error occurred while loading the content.

YAHOO.augment and prototypes

Expand Messages
  • randomjuju
    Hi there! I have a question about the design of the YAHOO.augment function. As it stands now, it copies
    Message 1 of 1 , Dec 29, 2006
    • 0 Attachment
      Hi there!

      I have a question about the design of the YAHOO.augment function.  As it stands now, it copies properties from the prototype of one object to the prototype of another.  I'm wondering why the source of the properties must be a prototype (it makes perfect sense that the definition be one).

      When I first read the augmentation docs, I envisioned a design pattern (that I'm still very fond of) where objects containing properties and methods defining and implementing a set of capabilities would be grafted onto more basic objects to extend their functionality.   To me, that suggests that the objects would be just that -- objects, and not necessarily the prototypes of other objects.  For example, if I had a basic "shape" object and wanted to do augment it with circle "capabilities," I might do something like this:

      ----
      Shape = function()
      {
      }

      Circle = function()
      {
      }

      YAHOO.extend(Circle, Shape);

      CircleCapabilities = {
      getRadius: function() { ... },
      getCircumference: function() { ... },
      ...
      };

      YAHOO.augment(Circle, CircleCapabilities);
      ----

      Instead, what I actually need to do is something more like this:

      ----
      ...
      CircleCapabilities = function()
      CircleCapabilities.prototype = {
      getRadius: function() { ... },
      getCircumference: function() { ... },
      ...
      };
      ...
      ----

      Not that this is the end of the world or anything.  It just seems a bit odd to me.  If I were to propose a change given my limited understanding of the situation, I would suggest that YAHOO.augment copy properties from the source directly if the source doesn't have a prototype property set.

      Again, my understanding of the situation is limited.  I feel like there's some other, better-thought-out idea of what YAHOO.augment could and should be used for.  What were the design goals with YAHOO.augment, and how are people using it now?

      Thanks!

      -Jon
    Your message has been successfully submitted and would be delivered to recipients shortly.