良い一日!
私は数日前に個人的な使用と配布のために独自の基本的な JavaScript ライブラリを書き始めましたが、メソッドの 1 つ、具体的にはbind()に問題があります。
メソッド自体の中で、これはライブラリ、つまりオブジェクトを指します。
Google にアクセスしてfunction.call()を見つけましたが、計画どおりには機能しませんでした。関数を実行しただけです。
別のメソッドeach()を見ると、 call()を使用して値を渡していることがわかります。
私も次のことを試しました:
f.arguments[0]=this;
私のコンソールは、「未定義」の「0」を読み取ることができないというエラーをスローします。
イベントリスナーで使用するために、これを渡すことができるようにしたいと思います(ライブラリを参照します--ウィンドウではありません)。
この JSFiddleの JavaScript の 195 行目から確認できます。
ここにもあります:
bind:function(e,f){
if(e.indexOf("on")==0){
e=e.replace("on","");
}
if(typeof f==='function'){
/*Right now, 'this' refers to the library
How can I pass the library to the upcoming eventListener?
*/
//f=f(this); doesn't work
//f.call(this); //doesn't work
//this.target refers to the HTMLElement Object itself, which we are adding the eventListener to
//the outcome I'm looking for is something like this:
/*$('h3').which(0).bind(function({
this.css("color:red");
});*/
//(which() defines which H3 element we're dealing with
//bind is to add an event listener
this.target.addEventListener(e,f,false)
}
return this;
},
貢献者の皆様、ご協力ありがとうございました。