<!--Introducing the core JS file--
<script type= "Text/javascript" src= "Commonutil.js" ></script>
<script type=text/javascript charset=utf-8>
<!--JS design mode (Factory mode)--
//Build a factory environment
//Car Shop
function Carshop () {};
carshop.prototype={
Constructor:carshop,
sellcar:function (type) {//Sell vehicle Method
var car;//declares a variable
switch (type) {
Case ' Benz ': car=new Benz ();
Case ' BMW ': Car=new BMW ();
Case ' Audi ': Car=new Audi ();
DEFANLT: ' Not buy it ';
}
//test Interface Implementation
Jalja. Interface.ensureimplements (car,carinterface);
return car;
}
};
var carinterface =new Jalja. Interface ("Carinterface", [' Start ', ' Run ']);
//Parent class of all vehicles
function Basecar () {};
basecar.prototype={
Constructor:basecar,
start:function () {
Alert (This.constructor.name + ": Start");
},
run:function () {
Alert (this.constructor.name + ": Run");
}
}
//Specific car
function Benz () {};
//Inheritance--put in front of unique attributes
jalja.extend (benz,basecar);
//define your own unique properties
benz.prototype.driverbenz=function () {
alert ("Benz unique 1");
};
function Bmw () {};
//Inheritance--put in front of unique attributes
jalja.extend (bmw,basecar);
//define your own unique properties
bmw.prototype.driverbmw=function () {
alert ("BMW unique 1");
};
function Audi () {};
//Inheritance--put in front of unique attributes
jalja.extend (audi,basecar);
//define your own unique properties
audi.prototype.driveraudi=function () {
alert ("Audi-specific 1");
};
//Test
var shop =new carshop ();
var car1=shop.sellcar (' Audi ');
Car1.run ();
Car1.start ();
Car1.driveraudi ();
var car2=shop.sellcar (' Benz ');
Car2.run ();
Car2.start ();
Car2.driverbenz ();
</script>
JS design mode (Factory mode environment Setup)