-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create 2012-12-28-undefined-props-on-numbers.md
New post about unexpected undefined properties on numbers Signed-off-by: DTrejo <david.daniel.trejo@gmail.com>
- Loading branch information
1 parent
ec35a2e
commit 3e2d387
Showing
3 changed files
with
18 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
``` | ||
function getBounds(node) { | ||
var n = node || 0; | ||
return { width: n.width, height: n.height }; | ||
} | ||
``` | ||
|
||
If you call `getBounds()` with _null_, you'll get back `{ width: undefined, height: undefined }` | ||
because in JS, numbers have properties (inherited from Number), and using an undefined | ||
property doesn't throw, it just returns undefined. `null` and `undefined` are propertyless. | ||
Definitely not what I expected in a quick reading of code like this. | ||
|
||
— [@unwiredben][1] | ||
|
||
[1]:https://twitter.com/unwiredben |