Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

angular.equals issue with objects containing custom toString methods. #10425

Open
jdalton opened this issue Dec 11, 2014 · 4 comments
Open

angular.equals issue with objects containing custom toString methods. #10425

jdalton opened this issue Dec 11, 2014 · 4 comments

Comments

@jdalton
Copy link
Contributor

jdalton commented Dec 11, 2014

angular.equals({}, { 'toString': function() { return 'custom'; } });
// => true (expected false)

I think this is due to the isFunction check in.

@caitp
Copy link
Contributor

caitp commented Dec 11, 2014

Yep --- this affects any function property where the same property name is a function in both objectA and objectB, regardless of where in the prototype chain it is. http://plnkr.co/edit/YO9qE7A858Dm4Ect7jwN?p=preview --- obviously O.p methods are going to be the more common problems, though.

@caitp
Copy link
Contributor

caitp commented Dec 12, 2014

There's a test case in the tree,

    it('should ignore functions', function() {
      expect(equals({func: function() {}}, {bar: function() {}})).toEqual(true);
    });

so presumably this is the desired behaviour ._. How much of a problem is this?

@petebacondarwin
Copy link
Contributor

The angular.equals purposefully ignores methods on objects as it is assumed that they are helper methods and do not define the object's identity. This is important for duck-typing behaviour.

Closing since this is the expected behaviour and documented in the API docs: https://docs.angularjs.org/api/ng/function/angular.equals

During a property comparison, properties of function type and properties with names that begin with $ are ignored.

@petebacondarwin
Copy link
Contributor

OK, so let's put this in the ice box and return to it if we get a real life use case that is breaking someone's app.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants