0

I was wondering if the following code is executed, does it inherit local variables from the NewDragDrop function? Does it matter if the NewDragDrop() is the constructor of another class?

function NewDragDrop (imageReference, imageTitle){
       var image;
       var title;
}

function InheritDragObject (imageReference, title){

       $.extend(true, this, new NewDragDrop(imageReference, title));
}
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
  • 2
    Not my downvote, but you can try this out fairly easily. Simply execute this code then do something like `var d = new InheritDragObject("ref", "title")` and inspect the result. Then if you don't understand the result, post a question asking someone to explain it. – Ray Toal Aug 13 '12 at 14:10
  • When you use `$.extend` like that, all `NewDragDrop` prototype methods are copied as own properties to the `InheritDragObject` instances, which defeats the purpose of having prototypes (as method containers) in the first place. Either use pseudoclassical inheritance (with functions), or use prototypal inheritance with `Object.create`. The `$.extend` method is not adjusted for inheritance - it serves other purposes. – Šime Vidas Aug 14 '12 at 12:56

0 Answers0