javascript - Trying to instantiate an animation class, getting "object is not a function" -


i'm trying instantiate class :

var drawcrash = new drawcrash; 

but i'm getting typeerror: object not function.

i've defined class -

var drawcrash = {      //private variables    canvas : ge1doot.canvas(),    particles: "",    nbrparticles : 160,    speed : 6,    strength : .4,    radius : 4,    perspective : 0.5,    ang : null,    cosorsin1 : null,    cosorsin2 : null,    enum : {    	wobble : "wobble",    	twirl : "twirl"    },    setdrawing : function (type) {    	if (type === this.enum.twirl){    	    blah blah blah    		this.cosorsin2 = math.sin;    	} else if (type === this.enun.wobble){    		blah blah blah    	} else {alert("wrong enum drawcrash");}    },    startdrawing : function () {      blah blah blah    }   }

is there wrong syntax?

that not how instanciate object in javascript.

a "class" in world function:

function drawcrash() {    //private variables   var canvas = ge1doot.canvas()     particles: "",     nbrparticles : 160,     speed : 6,     strength : .4,     radius : 4,     perspective : 0.5,     ang : null,     cosorsin1 : null,     cosorsin2 : null,     enum : {       wobble : "wobble",       twirl : "twirl"     },     setdrawing : function (type) {       if (type === this.enum.twirl){         blah blah blah         this.cosorsin2 = math.sin;       } else if (type === this.enun.wobble){         blah blah blah       } else {alert("wrong enum drawcrash");}    },    startdrawing : function () {      blah blah blah    }  } 

and can instanciate it:

var drawcrash = new drawcash(); 

however of variables seem private on object. want expose public, need put them on "this":

function drawcash() {   // private variables   var someprivatevar = 42;    // public variables   this.publicvar = "hello"; }  var drawcash = new drawcash(); drawcash.publicvar; // returns "hello" drawcash.someprivatevar; // undefined 

finally, in order define method on "class" in effective way, need extend object prototype (javascript prototype oriented language):

function drawcash() { ... }  drawcash.prototype.somemethod = function() { ... }  var drawcash = new drawcash(); drawcash.somemethod(); 

you can learn more reading article instance:

http://www.phpied.com/3-ways-to-define-a-javascript-class/


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -