How can I determine the instance of an object created using an AngularJS
factory?
angular.module('so')
.factory('UserFac', function () {
return function (first, last) {
return {
name : first + ' ' + last
};
}
})
.controller('UserCtrl', function (User) {
var user = new UserFac('John', 'Doe');
function checkUserInstance(userObj) {
// your answer here...
}
if (checkUserInstance(user)) {
// implementation doesn't matter
}
});
I've tried common JavaScript methods like:
user instanceof UserFac
and
typeof user === 'UserFac'
as well as
user.constructor === UserFac
and
user.prototype === UserFac
However, it seems that the internal workings of AngularJS
hide the prototype/constructor property for factories/services.
Searching online has been challenging, as most results discuss the distinction between service and factory.
Any assistance would be appreciated. Thank you!