Code Review Stack Exchange is a question and answer site for peer programmer code reviews. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a JavaScript/PHP file uploader and I want to start this project off on the right track. I've started with this, a JavaScript Uploader object which will handle Ajax calls, display progress, show error messages, etc. I'm just hoping to get some feedback on the way I'm setting up my scripts.

function Uploader(method) {

if(arguments.callee._singleton) return arguments.callee._singleton;
var _this = arguments.callee._singleton = this;

_this.opts = {
        1:"No file/folder selected",
        2:"Invalid file/folder type",
        3:"File/folder exceeds upload size"

_this.methods = {

    init: function(options) {
        for(var o in options) {
            _this.opts[o] = options[o];


    setup: function() {



if(_this.methods[method]) return _this.methods[method].apply(this,, 1));
else if(typeof method === "object" || !method) return methods.init.apply(this, arguments);

share|improve this question
Can you elaborate on how exactly you'll be using this Uploader object? The _singleton code at the very top and the code at the very bottom (as well as the use of a local _this variable) is confusing. – seand Jan 30 '12 at 0:31

Why not use an existing ajax file upload library, like Fine Uploader?

As for your code.


I think you meant to return _this.methods.init.apply(this, arguments);.


You should rewrite Uploader to not use arguments.callee for two reasons; it makes your code harder to read and for the browser to optimize.

share|improve this answer
Not to mention arguments.callee isn't supported in ECMAScript 5. – bob_cobb Nov 5 '12 at 17:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.