Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number constructor issue #1927

Closed
f-xyz opened this issue Jul 5, 2015 · 3 comments
Closed

Number constructor issue #1927

f-xyz opened this issue Jul 5, 2015 · 3 comments
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@f-xyz
Copy link

f-xyz commented Jul 5, 2015

Babel somehow changes Number constructor behavior. It breaks number comparison in Chai.js assertion library.

Example code: 1.js

'use strict';

var numberObject = new Number(1);

console.log(numberObject);
console.log('\n');

console.log(numberObject.constructor(numberObject));
console.log(Number(numberObject));
console.log(Number.prototype.constructor(numberObject));
console.log('\n');

console.log(typeof numberObject.constructor(numberObject));
console.log(typeof Number(numberObject));
console.log(typeof Number.prototype.constructor(numberObject));
console.log('\n');

console.log(numberObject.constructor === Number);
console.log(numberObject.constructor === Number.prototype.constructor);
console.log('\n');

console.log(Number.toString());
console.log(numberObject.constructor.toString());
console.log('\n');

Output of node 1.js

[Number: 1]


1 // it's a number
1
1


number // it's a number
number
number


true
true


function Number() { [native code] }
function Number() { [native code] }

Output of babel-node 1.js (the same for require('babel/register'))

[Number: 1]


[Number: 1] // it shouldn't be an object
1
1


object // it shouldn't be an object
number
number


true
true


function Number() { [native code] }
function Number() { [native code] }
@zloirock
Copy link
Member

zloirock commented Jul 5, 2015

Strange. Please, open issue in core-js repo.

@zloirock
Copy link
Member

zloirock commented Jul 5, 2015

Heh. Problem in constructor detection here. In your strange case this instanceof Number, like in new Number. Need add slow classof Object#toString.call check =\ As I say, please, open issue in core-js repo and it will be fixed in next release.

@f-xyz f-xyz closed this as completed Jul 5, 2015
@f-xyz f-xyz reopened this Jul 5, 2015
@f-xyz
Copy link
Author

f-xyz commented Jul 5, 2015

Created issue zloirock/core-js#89

zloirock added a commit to zloirock/core-js that referenced this issue Jul 5, 2015
@zloirock zloirock closed this as completed Jul 5, 2015
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 14, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

2 participants