Hello out there!
Vereinfachter Code:
// aus molilys Artikel Organisation von JavaScripten
// [link:http://aktuell.de.selfhtml.org/artikel/javascript/organisation]
Function.prototype.bindAsEventListener = function (object) {
var method = this;
var wrapper = function (event) {
method.call(object, event || window.event);
};
return wrapper;
};
function bar(n) {
alert("Output: " + n);
}
function Foo(n) {
this.value = n;
var button = document.createElement("button");
document.body.appendChild(button);
button.appendChild(document.createTextNode("Click me!"));
button.onclick = window.bar.bindAsEventListener(this.value);
}
window.onload = function() {
var foo = new Foo(42);
}
So geht’s nicht; es wird "Output: [object MouseEvent]" ausgegeben.
Wie übergebe ich 'this.value' aus Foo an die Funktion bar?
(Es soll im Script viele Instanzen von Foo geben.)
See ya up the road,
Gunnar
--
“Remember, in the end, nobody wins unless everybody wins.” (Bruce Springsteen)
“Remember, in the end, nobody wins unless everybody wins.” (Bruce Springsteen)