<html>
<head>
<script type="text/javascript">
function test (){
//refer tst to a new Objy object.
var tst = new Objy();
alert(tst.display());
}
function Objy(){
try{
this.prototype.display= function() {
this.text="yoyo";
};
}
catch (err){
alert (err);
}
}
</script>
</head>
<body onload="Javascript: test()">
<div id="display" >
</div>
</body>
</html>
Hi,
I'm basically experimenting with javascript's object and classes. Can someone figure out why it's giving me this error? "TypeError:Cannot set property 'display' of undefined".
It works if it was just like this (if there's no method for the Objy class):
function test (){
var tst = new Objy();
alert(tst.text);
}
function Objy(){
this.text="yoyo";
}
As soon as I add the
this.prototype.display=function(){
}
according to the exception thrown it says "TypeError:Cannot set property 'display' of undefined"
Is my syntax wrong or am i suppose to declare or define display? (I don't know if you're suppose to define a method head):confused: