开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜