Although for the particular use you are giving in your example may work, the promises are designed to work with return values normally asynchronous, which are basically the daily bread in JavaScript (ajax etc ...).
To give an example, imagine that with your implementation you will do an asynchronous calculation, such that:
var a = new chuleriaClass(function () {
console.log("Constructor");
});
a.then(function (e) {
console.log(1, this);
setTimeout(function() {//calculo asincrono de errorStr.
e.errorStr = "Hola que tal";
}, 200);
}).then(function (e) {
console.log(2);
console.log(e.errorStr);
}).error(function (e, msg) {
console.log("Call back de error : de p " + e.errorStr);
});
Your current implementation does not print the error valueStr.
Now using the native api of the promises we see that if we learn the new value even if it is an asynchronous calculation.
var a = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve("calculo async terminado");
}, 200)
}).then(function(res){
console.log('res', res);
});
This is an advantage of using the promises of JavaScript.
Some others that your implementation does not control are:
- Do not fall into the 'hell of the callbacks'.
- Error handling.
- Calculation of several promises at par.
- Shoot event when the asynchronous call ends.
- Standard usage quite widespread.
- Etc ...