Created
July 16, 2013 04:04
-
-
Save mrcsparker/6005670 to your computer and use it in GitHub Desktop.
Playing with Javascript sub-classing and data hiding
This file contains 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 Sample = (function (Sample) { | |
"use strict"; | |
var SampleColumn = (function () { | |
var SampleColumn = {}; | |
SampleColumn.parseColumns = function () { | |
var columns = [], | |
column = {}, | |
i; | |
for (i = 0; i < Math.floor((Math.random() * 100) + 1); i += 1) { | |
column["COL" + i] = "VAL" + i; | |
columns.push(column); | |
} | |
return columns; | |
}; | |
return SampleColumn; | |
}()), | |
SampleSheet = (function () { | |
var SampleSheet = {}; | |
SampleSheet.create = function (sheetName) { | |
var sheet = {}; | |
sheet[sheetName] = SampleColumn.parseColumns(); | |
return sheet; | |
}; | |
return SampleSheet; | |
}()), | |
SampleWorkbook = (function () { | |
var SampleWorkbook = {}, | |
sheetNames = [ 'First', 'Second', 'Third', 'Fourth', 'Fifth' ], | |
sheets = []; | |
SampleWorkbook.create = function (fileName) { | |
var i; | |
for (i = 0; i < sheetNames.length; i += 1) { | |
sheets.push(SampleSheet.create(sheetNames[i])); | |
} | |
return { | |
name: fileName, | |
sheets: sheets | |
}; | |
}; | |
return SampleWorkbook; | |
}()); | |
function createWorkbookFromFile(fileName) { | |
return SampleWorkbook.create(fileName); | |
} | |
Sample.parseFile = function (f) { | |
return createWorkbookFromFile(f); | |
}; | |
return Sample; | |
}(Sample || {})); | |
var output = Sample.parseFile("fileName"); | |
console.log(output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment