Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Overriding A Function 2

Status
Not open for further replies.

Elcid32

Programmer
Jul 28, 2006
10
US
Hello Fourm!

I have a question for ya. Is it possible to redefine a function in Javascript? For example:
Code:
function myTest(){

  this.showAlert = function(){
    alert('Show Me!')
  }
  this.callAlert = function(){
    this.showAlert();
  }
}
test = new myTest;
test.showAlert = function(){ alert('No! Show Me Instead')}
test.callAlert;

Thanks!
 
As Jeff hints at, your above code overrides the function with no problems. You are seeing no results because you are missing 2 sets of brackets:

Code:
function myTest(){

  this.showAlert = function(){
    alert('Show Me!')
  }
  this.callAlert = function(){
    this.showAlert();
  }
}
test = new myTest[!]()[/!];
test.showAlert = function(){ alert('No! Show Me Instead')}
test.callAlert;[!]()[/!]

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you both for your responses - I appreciate the help.

Shawn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top