最近接触前端,开始学习JS、初涉jQuery,有点困扰 this 和 ${this} 的区别,搜了一下资料,做了简单的测试,现做一小结。
jQuery中 ${...} 相当于 一个 jQueryObj 的生成器,对于同一个元素对象,多次“包装”时实际会创建多个 jQuery 对象(当然它们都是对该元素对象进行操作)
注意以下输出
alert(this == this) // true
alert($(this) == $(this)) //false
此外,由于javascript中对象的赋值为值传递,以下输出为true
var jObj1 = $(this);
var jObj2 = jObj1;
alert(jObj1 == jObj2); //true