I use Angular 1.5 and I made a factory function which is return a literal object like this:
return {
item: null,
get: function() {
return item;
},
create: function() {
if (this.get()){
this.remove();
}
this.item = {};
},
remove: function() {
var item = this.get();
if (item) {
this.item = null;
}
},
add: function() {
if (!this.get()) {
this.create();
}
this.item.newprop = 'value';
}
}
-
please do not ask me to change to function declaration. I want a object with his own actions(functions) and properties that is working on.
-
This pattern (like
get
insidecreate
so on..) I didn't copied from anywhere. so I'm wonder if has a name? It is best way to deal with function-black boxes? -
What is the best way to put Promise inside? so every function should return a promise
-
every
then
function I need to usebind
???todo like this:
create: function () { this.get() .then(remove) .then(function () { this.item = {}; // BUT this === undefined!! }); }
Aucun commentaire:
Enregistrer un commentaire