Skip to content

Instantly share code, notes, and snippets.

@ArielLeslie
Created October 6, 2015 17:34
Show Gist options
  • Save ArielLeslie/55bd17cd8a4453e02733 to your computer and use it in GitHub Desktop.
Save ArielLeslie/55bd17cd8a4453e02733 to your computer and use it in GitHub Desktop.
Make Properties Private
//Let's create an object with a two functions. One attached as a property and one not.
var Car = function() {
this.gear = 1;
function addStyle(styleMe){
return 'The Current Gear Is: ' + styleMe;
}
this.getGear = function() {
return addStyle(this.gear);
};
};
var Bike = function() {
// Only change code below this line.
speed = 100;
function addUnit(value) {
return value + "KM/H";
}
this.getSpeed = function () {
return addUnit(speed);
};
};
// Only change code above this line.
var myCar = new Car();
var myBike = new Bike();
if(myBike.hasOwnProperty('getSpeed')){(function() {return JSON.stringify(myBike.getSpeed());})();}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment