I have come across two different JavaScript testable patterns, but I am struggling to understand the distinctions between them and which one would be more suitable for my needs.
Pattern 1:
function MyClass () {
this.propertyA = null;
this.methodA = function() {
alert('');
}
}
var object = new MyClass();
object.methodA();
Pattern 2:
var object = (function() {
var propertyA = null;
return {
methodA: function() {
alert('');
}
}
}());
var object = new MyClass();
object.methodA();
What sets these patterns apart? Which one is more suitable for unit testing using jQuery's QUnit? It's worth noting that I cannot utilize jQuery plugins due to specific requirements focused on business logic (no UI testing). Thank you for any guidance you can provide.