$.each(["foo","bar"],function(){console.debug(this);});
将字符串类型的“foo”和“bar”转换为字符串对象中的等价物。
鉴于...
$.each(["foo","bar"],function(i,e){console.debug(e);});
将保留“foo”和“bar”的原始字符串类型。
我想知道为什么 $.each 会进行转换?而且,更重要的是......这种转换永远不会发生 - 保持字符串不变,无论它们是字符串类型还是字符串对象?
最佳答案
(The value can also be accessed through the this keyword, but Javascript will always wrap the this value as an Object even if it is a simple string or number value.)
这表明它是 Javascript,而不是 jQuery 正在执行转换。
在回调函数中使用值的情况下,jQuery 传递该值本身,因此它可以保留其类型。
关于javascript - jQuery:从字符串类型转换为$.each中的字符串对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10432748/