View Single Post
Old 01-04-2013, 09:31 PM   PM User | #6
DaveyErwin
Regular Coder

 
Join Date: Aug 2010
Posts: 809
Thanks: 12
Thanked 168 Times in 166 Posts
DaveyErwin is on a distinguished road
Lots of ways to do this
here is one ....

Code:
 
<script>
Ship = function (){
    var speed = 0;
    return function (color){
 this.faster = function(){speed+=1}
 this.color=color;
 this.animate = function(){
     return speed;}
    }
}();
a= new Ship("red");
b= new Ship("blue");
alert(b.color + " ship speed = "+b.animate());
b.faster();
alert(b.color + " ship speed = "+b.animate());
alert(a.color + " ship speed = "+a.animate());
a.faster();
alert(a.color + " ship speed = "+a.animate());
</script>
DaveyErwin is offline   Reply With Quote