---
title: "浅谈 jQuery 中的 this 和 ${this}"
author: "jupiterpan"
date: "2011-03-23T12:41:54Z"
tags: []
categories: ["Web前端"]
slug: "jquery-this-this"
draft: false
lastmod: "2011-03-23T12:41:54Z"
id: 972496
url: "https://jstyle.iteye.com/blog/972496"
---

最近接触前端，开始学习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