This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. the basic javascript object creation | |
function Car(type) { | |
this.speed = 0; | |
this.type = type || "No type"; | |
this.drive = function(newSpeed) { | |
this.speed = newSpeed; | |
} | |
} | |
var bmw =new Car("BMW"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Car(type) { | |
this.type = type; | |
this.speed = 0; | |
this.func = function() { | |
return this.type; | |
} | |
} | |
var bmw = new Car("BMW"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the prototype object | |
function Hero(type) { | |
//properties of this proto object | |
this.strength = 0; | |
this.type = type || "No type"; | |
} | |
// proto function, used by all | |
Hero.prototype.attack = function(newStrength) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ns; | |
(function (ns) { | |
ns.Car = function (type) { | |
this.speed = 0; | |
this.type = type || "No Type"; | |
} | |
ns.Car.prototype = { | |
drive: function(newSpeed) { | |
this.speed = newSpeed; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
○ Building blocks for writing modules. | |
○ A façade is a high level interface to a larger code base that hides the underlying code complexity. | |
○ The facade exposes an application programming interface (API) which limits the available functionaity we can use and helps encapsulate a lot of the interior code behavior. | |
Façade Pattern Structure in JavasScript | |
• the function returns an object | |
• the object acts a a façade to the inner implementation , which is encapsulated. | |
*/ |
OlderNewer