<input type='button' id='btn' value='click' />
<script type="text/javascript">
var jObject = {
bind : function(){
var o = document.getElementById('btn');
o.onclick = function(){
// How can I find caller from here ?
}
}
};
jObject.bind();
</script>
MISE À JOURComment puis-je trouver l'appelant de la fonction interne?
Je lis un truc d'ici - http://www.mennovanslooten.nl/blog/post/62
Et maintenant je peux obtenir jobject dans la fonction intérieure.
<input type='button' id='btn' value='click' />
<script type="text/javascript">
var jObject = {
bind : function(){
var o = document.getElementById('btn');
o.onclick = function(jObj){ // 1. add this
return function(){ // 3. wrap with return function(){ ... }
alert(jObj); // 4. now I can get jObject here.
}
}(this); // 2. and this
}
};
jObject.bind();
</script>
Que voulez-vous dire par l'appelant? – epascarello
L'appelant est quelqu'un qui appelle la fonction. Exemple dans le code ci-dessus, Caller est le bouton (id = btn). – diewland