0

Possible Duplicate:
Is there an equivalent of PHP's 'parent' with javascript prototypal inheritance?
Override a base class function

I have a base class/prototype & a child class/prototype in Javascript.

Is it possible to make the child class override a base classes privileged function?

I know I am trying to treat javascript as an OO language which its not but you never know this maybe possible?

If its possible could you give an example how I do this?

function baseClass()
{
   this.privFunct() {}
}

function childClass()
{
   this.privFunct() 
   {
      var baseFunct = baseClass.prototype.privFunct;
      this.baseFunct();
      // no do some object specific actions here
   }
}
Community
  • 1
  • 1
sazr
  • 24,984
  • 66
  • 194
  • 362
  • 1
    It would be great if you could give a complete example with which we can comprehend how all the pieces are put together. Don't simplify/pseudocodify too much. So far `this.privFunct` does not seem to a property of `baseClass.prototype` and it might also depend how you actually implement inheritance. More information needed. And fwiw, JavaScript *is* an OO language. – Felix Kling Nov 06 '11 at 22:28
  • 1
    JS is an OO language. Do you mean "treat JS as a class-based language"? What's your definition of "privileged"? Lastly, the sample code isn't valid. `this.privFunct() {}` isn't a valid declaration, and `var baseFunct` doesn't create a property named `baseFunct` on `this`. – outis Nov 06 '11 at 22:29
  • Have a look at the `Function.apply` or `Function.call` methods. One link to start off: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/Apply – Rob W Nov 06 '11 at 22:34
  • Ok I added an example that has context, ie, displays what I am trying to do – sazr Nov 06 '11 at 22:55
  • Dup of [Calling base method using javascript prototype](http://stackoverflow.com/questions/560829/calling-base-method-using-javascript-prototype), [Is there an equivalent of PHP's 'parent' with javascript prototypal inheritance?](http://stackoverflow.com/questions/5508393/is-there-an-equivalent-of-phps-parent-with-javascript-prototypal-inheritance) – outis Nov 06 '11 at 23:34

0 Answers0