0
   

Assign object function preserving "this"

 
 
Reply Fri 7 Aug, 2009 01:56 pm
Hi,

I would like to know if this is possible in some way?

var $object1 = {
$id : 1,
test : function()
{
alert(this.$id);
}
};

var $object2 = new function()
{
this.$id = 2;
this.test = function()
{
alert(this.$id);
};
//ASSIGN OBJECT1 WITH THIS INTERNAL FUNCTION
$object1.test = this.test;
};

$object1.test();
$object2.test();

The result I was must be that both $object1 and $object2 alert with the number 2.

Thanks!
  • Topic Stats
  • Top Replies
  • Link/Embed
Type: Question • Score: 0 • Views: 149 • Replies: 0
No replies

 
 

Related Topics

I'm the developer - Discussion by Nick Ashley
how to earn money in internet - Discussion by rizwanaraj
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
The version 10 bug. Worse then Y2K! - Discussion by Nick Ashley
CSS Border style colors - Question by meesa
There is no Wisdom in Crowds - Discussion by ebrown p
mod rewrite for a different theme? - Discussion by etali
 
  1. able2know
  2. » Assign object function preserving "this"
Copyright © 2009 Horizontal Verticals :: Page generated in 0.33 seconds on 11/23/2009 at 07:22:31 Top End