/ Published in: ActionScript 3
URL: http://www.gotoandlearn.com/play.php?id=159
Watch Lee Brimelow's tutorial on GotoAndLearn to see what this is all about.
Expand |
Embed | Plain Text
<!----------------------------------------------------------------------- -- index.html -- -- Demo JavaScript file containing a self-executing anonymous function -- Taken from here Lee Brimelow's tutorial ... -- http://www.gotoandlearn.com/play.php?id=159 --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>OOP JavaScript</title> <script src="js/Car.js"></script> <script> function init() { var car = new Car("Audi", "Ranger", "Blue"); car.setMake("Ford"); car.startEngine(); } </script> </head> <body onload="init()"> </body> </html> ///////////////////////////////////////////////////////////////////////// // Car.js // // Demo JavaScript file containing a self-executing anonymous function // Taken from here Lee Brimelow's tutorial ... // http://www.gotoandlearn.com/play.php?id=159 (function(window) { //Public variable/property Car.prototype.mpg = 30; //Static variable/property Car.num_of_wheels = 4; //Constructor function/method function Car($make, $model, $colour) { //Private variables/properties var _make = $make; var _model = $model; var _colour = $colour; //Public getters this.getMake = function(){return _make;}; this.getModel = function(){return _model;}; this.getColour = function(){return _colour;}; //Public setters this.setMake = function($make){_make = $make;}; this.setModel = function($model){_model = $model;}; this.setColour = function($colour){_colour = $colour;}; } //Public function/method Car.prototype.startEngine = function() { console.log(getDesc(this) + " engine started"); }; //Private function/method function getDesc($context) { return $context.getMake() + " " + $context.getModel(); } //Make available in the global scope window.Car = Car; }(window));
You need to login to post a comment.
