Javascript tag ? syntax question
I came across the following c开发者_StackOverflow中文版ode snippet and am confused about what the not:
is doing. Is it a tag? If so, are there any other uses for it?
var foo = {
not: function(bool) { return !bool; }
}
Can you provide me with a possible use scenario for this kind of syntax?
This is not a tag.
It is declaring an object with a property called "not" which is a function.
You can find more details at JSON and Javascript syntax
In Javascript the syntax { property: value }
creates an object with the property property
, whose value is value
. So your code defined an object which has the property not
, whose value is a function which returns the negation of its argument.
精彩评论