开发者

Empty string + variable: why?

The following is a line from Backbone.js:

return this._escapedAttributes[attr] = escapeHTML(val ==开发者_如何学运维 null ? '' : '' + val);

What is the point of '' in '' + val? Wouldn't +val suffice?


'' + val concats val to an empty string, which results in val being converted to a string. +val converts val to a number instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜