Cybercrux

Everything is achievable through technology

Module

var bike = (function () {
var isMoving = false,
isMovingSetter = function (value) {
isMoving = value;
},
test = function () {
console.log(‘The bike is moving? ‘ + isMoving);
};
return {
IsMoving: isMoving,
Test: test,
IsMovingSetter: isMovingSetter
};
}());

// directly setting the property doesn’t change the value, this tripped me up for awhile
bike.IsMoving = true;
console.log(bike.IsMoving);
bike.Test();

// a setter is necessary
bike.IsMovingSetter(true);
bike.Test();

Advertisements