Last active
August 29, 2015 14:00
-
-
Save lovio/11107223 to your computer and use it in GitHub Desktop.
a usage of `~`
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
res.type = function(type){ | |
return this.set('Content-Type', ~type.indexOf('/') | |
? type | |
: mime.lookup(type)); | |
}; | |
# 判断Cotent-Type中是否有/,比如application/json | |
# 如果有就去查询mime | |
# 在js中, null, undefined , '' 以及0都是false | |
# ~-1 === 0 | |
# ~按位取反 | |
# 这样就避免了使用 ~type.indexOf('/') === -1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment