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 to this Topic
Type: Question • Score: 0 • Views: 1,657 • Replies: 0
No top replies

 
 

Related Topics

Webdevelopment and hosting - Question by harisit2005
Showing an Ico File - Discussion by Brandon9000
how to earn money in internet - Discussion by rizwanaraj
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
THANK YOU CRAVEN AND NICK!!! - Discussion by dagmaraka
I'm the developer - Discussion by Nick Ashley
 
  1. Forums
  2. » Assign object function preserving "this"
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.05 seconds on 07/26/2024 at 10:11:01