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

typeOf method for better type checking #1398

Closed
wants to merge 1 commit into from
Closed

typeOf method for better type checking #1398

wants to merge 1 commit into from

Conversation

yasinuslu
Copy link

I just came by a very good article then i thought it would be good to have a method like that in underscore.js

@yasinuslu
Copy link
Author

I didn't realize npm test. Checking failure right away.

@yasinuslu
Copy link
Author

seems like a known problem: http://stackoverflow.com/questions/14218670/why-are-null-and-undefined-of-the-type-domwindow
code:

console.log("testing typeOf null:", _.typeOf(null));
console.log("testing typeOf undefined:", _.typeOf());
console.log("testing typeOf string:", _.typeOf("foo"));
console.log("testing typeOf null with typeof operator:", typeof null);
console.log("toString for null:", ({}).toString.call(null));
console.log("toString for string:", ({}).toString.call("foo"));

npm test (phantomjs 1.9.0) output:

testing typeOf null: domwindow
testing typeOf undefined: domwindow
testing typeOf string: string
testing typeOf null with typeof operator: object
toString for null: [object DOMWindow]
toString for string: [object String]

Chrome 31.0.1650.63 output:

testing typeOf null: null
testing typeOf undefined: undefined
testing typeOf string: string
testing typeOf null with typeof operator: object
toString for null: [object Null]
toString for string: [object String]

@akre54
Copy link
Collaborator

akre54 commented Jan 6, 2014

Hi @yasinuslu, this has been brought up and declined a few times in the past (an early one being #269). I think the reasoning still applies here.

@akre54 akre54 closed this Jan 6, 2014
@yasinuslu
Copy link
Author

Seems fair, thanks for fast reply.

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

Successfully merging this pull request may close these issues.

None yet

2 participants