I have some code that I'm refactoring, right now its just a list of functions, primarily jQuery.
The code is a form builder. The user adds sections, questions etc using jqueryUI drag/drop/sort. They can get quite long in the range of > 1k questions. I've been debating between patterns,frameworks, etc. and have settled on what I believe will be the best improvement without ripping everything out and starting completely over with something like angular or react.
I was also considering the module pattern but I'm concerned about having so many duplicates of the methods in memory (>1k) and thought this might serve me better. Is there anything I'm overlooking or gotchas that might cause an issue? I like that its all wrapped inside an IIFE and feels encapsulated.
Pattern example:
var Question = (function() {
function Question(name, type) {
// enforces new
if (!(this instanceof Question)) {
return new Question(name,type);
}
// constructor body
this.name = name || 'default' ;
this.type = type || 'text';
}
Question.prototype.someMethod = function(arg) {
// method body
}
return Question;
}());
it would be used like so:
Question question1 = new Question('name','picklist');