//constructor declaration
function CustomObject() {};
//using constructor to create an object
var myObj = new CustomObject();
myObj instanceof CustomObject;
// > true
//declare constructor function
function MyObject() { }
//create object with constructor
var myObj = new MyObject();
//constructor declaration with constructor arguments
function MyObject(dataObj) {
this.data = dataObj;
}
//use the arguments like this:
var myObj = new MyObject({items : 4});
console.log(myObj.data.items);
// > 4
function MyObject() {
return {
items : 3,
count : function(num) {
console.log(num);
}
}
}
function closureFunction() {
var closureVar = 'I come from a closure!';
function printOut() {
console.log(closureVar);
}
return printOut;
}
var closFunc = new closureFunction;
closFunc();