angular/angular.js

angular.equals(new String("a"), "a") return false

vinsonLan opened this issue · 3 comments

AngularJS is in LTS mode

We are no longer accepting changes that are not critical bug fixes into this project.
See https://blog.angular.io/stable-angularjs-and-long-term-support-7e077635ee9c for more detail.

I'm submitting a ...

  • regression from 1.7.0
  • security issue
  • issue caused by a new browser version
  • other

Current behavior:

Expected / new behavior:

Minimal reproduction of the problem with instructions:

AngularJS version: 1.8.x

Browser: [all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView | Opera XX ]

Anything else:

angular.equals(new String("a"), "a") return a false, is there a bug ?
the first parametor was parse from html, and parse to a String Object, then use angular.equals method, return me a false!!

image

it's that have any other effects if i rewrite like this?

While it might be somewhat unexpected, '...' and new String('...') are indeed different in JavaScript. The former is a string literal (it has a type of string) and the latter is a String object (it has a type of object).

It is debatable whether angular.equals() should treat them as equal or not, but given that AngularJS is in LTS mode this is not going to change. I don't see any problem in implementing it yourself if you like (as you showed above).