Tuesday, April 1, 2014

javascript classes - simulated using functions

Good resource for  Learn JavaScript Design Patterns
http://addyosmani.com/resources/essentialjsdesignpatterns/book/#detailmvc

Hello World Example for javascript classes - simulated using functions

Script
----------

<h2>Hello  javascript classes - simulated using functions</h2>
<script type="text/javascript">
    // A car "class"
    function Car( model ) {

        this.model = model;
        this.color = "red";
        this.year  = "2014";

        this.getInfo = function () {
            return this.model + " " + this.year;
        };

    }

    var myCar = new Car("toyota");

    myCar.year = "1999";

    console.log( myCar.getInfo() );


</script>