對於react native
繫結this
,我將其歸類為以下四種方式:
class
testbind
extends
react.component ;
}del()
render() >
this is a text);}
}
針對使用bind方法的繫結方式,還有一種優化方案,就是在constructor函式中繫結,這樣在效能上會有一定的優化。
class
home
extends
react.component ;
this.del = this.del.bind(this);
}del()
render() >
this is a text);}
}
class
home
extends
react.component ;
}del()
render() >
this is a text);}
}
還有一種使用箭頭函式定義函式的新寫法,我暫時將其歸類為第四種方法,將在下文中介紹。
該運算子現在還在草案階段,也不支援傳入引數,在es6中暫不支援。在形式上是這樣的:
class
home
extends
react.component ;
}del()
render() >
this is a text);}
}
class
home
extends
react.component ;
}del = () =>
render() >
this is a text);}
}
當需要傳入引數時,在呼叫的時候也需要使用箭頭函式來觸發
class
home
extends
react.component ;
}del = (text) =>
render() >
this is a text);}
}
對於react native
繫結this
,我將其歸類為以下四種方式:
jquery繫結事件以及js繫結事件
jquery繫結事件 bind事件 onelive delegate on對應的 jquery繫結click事件的寫法start click1 bind click function click2 one click function click3 live click function click...
JS this以及繫結丟失
繫結丟失,就是this的指向出現了改變,一般指的是this指向該物件卻指向了window 關於繫結丟失的情況有四種 1.函式名是別名 2.函式作為引數 3.跟第二種類似,出現在內建函式中 4.函式的賦值 以下討論這四種情況 1.function b var p p.b p var c p.b c 呼...
Python中sort以及sorted函式初探
help on built in function sorted in module builtin sorted sorted iterable,cmp none,key none,reverse false new sorted list help on built in function so...