Friday, August 19, 2011

Oops in Javascript - Part -1

In this post i will show you how to create Classes and object instance in Javascript.

var  myclass = function  (arg) {
console.log("Class initiated" );//Check object is initiated or not 
this .arg = arg;
myclass.prototype.myfunc = function  () {
console.log(this .arg);
function  TestOops() {
var  c = new  myclass("obj1" ); //create first instance for myclass
c.myfunc();//prints obj1 
var  d = new  myclass("obj2" );//create second instance for myclass
d.myfunc(); //prints obj2 
c.myfunc(); //prints obj1 

No comments:

Post a Comment