views:

32

answers:

1

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!

+1  A: 

You can use the with statement, but I do not recommend it.

SLaks
Still, a very powerful statement.
stagas
Thanks Slaks, I am familiar with with, and its pitfalls. I am slightly hesitant to use it but not totally opposed. It does sort of achieve what I want.Hopefully I can get some other ideas too.Thanks.
iamnotmad