angular: Object.prototype.toString() is overridden and behaves incorrectly
After updating to version 0.9, the Object.prototype.toString.call( undefined )
returns [Object Window]
instead of [Object Undefined]
when the strict
mode isn’t turned on.
The root of this bug is caused by this line:
https://github.com/angular/zone.js/pull/734/files#diff-7cf54420c5bf443f7d3575ad72ac1de3R44
where this
refers to the Window
in non-strict mode.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 24 (8 by maintainers)
When this fix will be released through npm ?
I found two workarounds:
1- Add the
.js
to the import in the pollyfills.ts in the Angular app:2- Disable the toString patching as specified in:
https://github.com/angular/zone.js/blob/master/MODULE.md
I added the following to the pollyfills.ts in the Angular app:
__Zone_disable_toString = true; // Zone will not patch Function.prototype.toString
This is not a zone.js issue, you can disable the monkey patch of zone.js for
toString()
by define(window as any).__Zone_disable_toString = true
in a file calledzone-flags.ts
and then import this file before importing zone.jsAfter this, the error still exists, the reason is
in IE, the base class
Window
is not a function, instead aObject
, so this issue can be reproduced by the following code.in
Chrome
, the type will befunction
, and in IE it will beObject
, so the error happened, so we need some other tricks toextends Window
in IE, but still this has nothing to do withzone.js
, I will do some research later about this issue, but will close this one for now.@ma2ciek, @cristhiank , thanks for posting the issue and providing the information, I will check it.
@cristhiank, thanks, could you try the latest version on master branch https://github.com/angular/zone.js/blob/master/dist/zone-evergreen.js to test again?