Question by
henrique.sAra · Sep 14, 2015 at 10:12 AM ·
classobjectsclasses
I can not use classes
Cod:
var _class = function(){
var value : int;
}
var myClass : _class;
function Start()
{
myClass = new _class();
}
error: "cannot convert 'void' to 'object' ".
Comment
I don't even know what this should do:
var _class = function(){ var value : int; }
is this a JS delegate? Where is the class _class defined?
Answer by nockieboy · Sep 14, 2015 at 09:12 PM
Try this:
function Apple (type) {
this.type = type;
this.color = "red";
this.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
}
You can instantiate the Apple class like so:
var apple = new Apple('macintosh');
apple.color = "reddish";
alert(apple.getInfo());
Might be worth you doing some tutorials on Javascript - I'd recommend Codecademy.
Your answer
Follow this Question
Related Questions
Trouble with creating objects 1 Answer
Unity 3D C# - Making Classes Act Like An Array 3 Answers
Assaigning objects in class 2 Answers
C# Find specific object by getting one of its variables 0 Answers