[ 2 posts ]

mingfai

  • Joined: Mon Dec 15, 2008 6:58 pm
  • Posts: 22
  • Offline
  • Profile

use Y.mix copy prototype method of object to another object?

Post Posted: Wed Feb 25, 2009 9:51 pm
+0-
Y.mix has a few mode to control the behavior of copying. i.e.
  • default(0): object to object
  • 1: prototype to prototype (old augment)
  • 2: prototype to prototype and object props (new augment)
  • 3: prototype to object
  • 4: object to prototype

given the following case:
var Foo = function() {}
Foo.prototype.name = 'foo'

var Bar = function() {}
Bar.prototype.name = 'bar'
Bar.prototype.sayMyName = function() { return this.name}

var newFoo = Y.mix(new Foo(), new Bar())

is there a mode that is suppose to copy the sayMyName function to newFoo? in my test, none of the modes work.

Adam Moore

YUI Contributor

  • Username: adam
  • Joined: Wed Sep 03, 2008 11:16 am
  • Posts: 356
  • GitHub: apm
  • Gists: apm
  • Offline
  • Profile
Tags:

Re: use Y.mix copy prototype method of object to another object?

Post Posted: Fri Feb 27, 2009 2:25 pm
+0-
By default, Y.mix will not overwrite existing properties. Pass true as the third parameter to allow it to overwrite, then the appropriate mode should work (I think the docs are clear enough for you to choose the right one).
  [ 2 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum