I’m building a wrapper for the HTML5 File(Reader) API with a fallback to normal file inputs or swfupload.
I have one general function “Uploader” and three sub functions (all in the same scope)
function Uploader() { }
function UploaderAPI() { }
function UploaderSWF() { }
function UploaderHTML() { }
The idea is that you create a var uploader = new Uploader() and that function calls one of the subfunctions, based on feature support/configuration.
However, I was wondering if there’s a way to prevent users from directly calling one of the subfunctions, and instead have them only available to Uploader().
Is this doable without moving them to the Uploader scope?
You could use the module pattern and define those functions as private methods (through closure) but this will move your functions inside another scope.
e.g.
Doing so you can choose to make some public methods available along with an instance and use those function inside it, but without call them directly e.g.
Example (working) fiddle: http://jsfiddle.net/ndQFB/