www.webdeveloper.com
Results 1 to 2 of 2

Thread: reassing object method that used object notation

  1. #1
    Join Date
    Mar 2009
    Posts
    5

    reassing object method that used object notation

    Hi, I am using an object written by someone else that was built like
    Code:
    MyObject = {
      MyMethod : function() {},
      ...
    }
    I thought I could do
    Code:
    MyObject.OldMethod = MyObject.MyMethod;
    MyObject.MyMethod = function() {
      MyObject.OldMethod();
      newstuff;
    };
    but it doesn't work. Can anyone explain why, suggest a way to achieve this? The original MyMethod is called in many other places so I just want to override it and let it rip.

    Thanks!!

  2. #2
    Join Date
    Jun 2007
    Posts
    667
    Code:
    MyObject.OldMethod = MyObject.MyMethod;
    MyObject.MyMethod = function() {
      this.OldMethod();
      //newstuff;
    };
    Y_U U_G_A_E_U_ B_S_A_D_

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles