Re: [問題] 如何取得父層函式的this
當然不一樣瞜..
這個function declaration 裡的this會refer到global object(就是你的window哩)
另外原作大概是筆誤寫了個匿名函式..
得給他個名字或是包起來才不會error
function myCoolFunction(){
this.hide() <---這邊的this
}
(function{
this.hide() <---這邊的this
})()
either way..
※ 引述《windwofswold ( ◤〔ζ狼ζ〕◢)》之銘言:
: 你要這種嗎XD
: $('#tt tr').click(function(){
: var self = this;
: function(){
: self.xxxx; // 父層的this
: this.hide()
: }
: });
: 如果第二個function 是包callback
: 他的this才會不一樣不是嗎@__@
: ※ 引述《genomini (不重要)》之銘言:
: : 假如
: : $('#tt tr').click(function(){ <--父層
: : function(){
: : this.hide() <---這邊的this
: : }
: : });
: : 請問有無指令是可以取得父層的this呢?
: : 還是說只能在外面多加一個變數存父層的this
: : 然後再子層呼叫那變數@@
: : 如
: : $('#tt tr').click(function(){ <--父層
: : var x = $(this);
: : function(){
: : x.hide() <---這邊的this
: : }
: : });
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 71.119.252.59
※ 編輯: senser 來自: 71.119.252.59 (07/17 03:38)
→
07/17 03:39, , 1F
07/17 03:39, 1F
推
07/19 13:54, , 2F
07/19 13:54, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 5 之 5 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章