Select to view content in your preferred language

Using Prototype

635
1
05-27-2013 07:19 PM
LTran
by
New Contributor
Here's my code:

var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");


var Shape = function(){}

Shape.prototype.Circle = function(){
 // Some code here
};

Shape.prototype.Square = function(){
 // Some code here
};


MainMenu.prototype = new Shape();

var MainMenu = function(ctx){
   this.draw{
 this.Circle();
 this.Square();
   }
}



What I want to do is to call the Circle() and Square() function inside my draw() function.
But it doesn't work.
Is this even possible??
I'm going crazy trying to figure this out!!
0 Kudos
1 Reply
VinayBansal
Frequent Contributor
<html>
<head>
    <title></title>
    <script type="text/javascript" language="javascript">
        var Shape = function () { }

        Shape.prototype.Circle = function () {
            alert("Calling circle");
        };

        Shape.prototype.Square = function () {
            alert("Calling Square");
        };

        var MainMenu = new Shape();

        MainMenu.draw = function (ctx) {            
            this.Circle();
            this.Square();
        };

        function callThisOne() {
            MainMenu.draw(null);
        }
    </script>
</head>
<body>
    <input type="button" value="Click" onclick="callThisOne();" />
</body>
</html>

Try this way.....
0 Kudos