Reputation: 13
I'd like someone to confirm for me that it's impossible to create an object that allows me to make both of the following calls in javascript:
user.remove();
user.remove.all();
Upvotes: 1
Views: 45
Reputation: 1276
No it's not impossible. functions are objects just like everything else. There is nothing to stop you doing the following:
function User() {
var remover = function (){
// do removal stuff
}
remover.all = function () {
// do remove all stuff
}
this.remover = remover;
}
Then just create the user as normal:
var user = new User();
Upvotes: 0
Reputation: 200
Sure you can. Here is an example.
var user = new Object();
user.remove = function () {
console.log("remove called");
}
user.remove.all = function (){
console.log("remove all");
}
user.remove();
user.remove.all();
Upvotes: 4