문제

I am following the example from coffeescript cookbook

and I am playing a bit with this example: http://jsfiddle.net/andilab/N8DP3/2/

normal_false = 1<2<2 #false -> is NOT printed

normal_true  = 1<2<3 #true -> is printed

wondering why false is not printed until used with JSON.stringify, is it matter of coffescript or JSFiddle or jQuery?

도움이 되었습니까?

해결책

This is caused by the use of jQuery's append function.

Append calls various things and at some point calls buildFragment to turn the argument provided into an HTML fragment to add.

In this function is the following:

if ( elem || elem === 0 ) {
    ... //Most of the code that generates stuff
}

elem in this case will be false and so it skips over it.

I assumed this line is defined to catch "undefined" things being passed in and just happens to catch false too. Further than this I can't say why the code is like this but its that line of code that does it.

Reference: http://code.jquery.com/jquery-2.1.0.js

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top