contain new elements of an "instance" in javascript

Posted by iamnotmad on Stack Overflow See other posts from Stack Overflow or by iamnotmad
Published on 2010-06-07T19:34:31Z Indexed on 2010/06/07 19:42 UTC
Read the original article Hit count: 190

Filed under:
|

Hi, so I know there are tons of ways to simulate inheritance and other OO features. I have chosen one to use for my project and am wondering if I can create an instance and add stuff to it and keep it contained (within braces). Consider the following:

function BaseClass(){
  <this.stuff here>
}

function SubClass(){
  this.superClass = BaseClass();
  this.superClass();

  <this.other stuff here>
}

myObj = new SubClass();

so myObj is an instance of SubClass. I can add things to myObj like:

myObj.blah = "funtimes";

What I would like is to be able to add stuff to the "instance" and keep it organized in braces much like the constructor. psuedo code like:

myObj = new SubClass() {
  var blah = "funtimes"
  <more instance specific stuff here>
}

Is something like this possible? Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jscript