Y
yawnmoth
Based on my understanding of the apply function, the following code
snippet should, at the very least, not yield any errors.
Unfortunately, it does, suggesting my understanding is... limited.
Any ideas as to what's wrong?:
<script>
function simpleClass(value) {
this.value = value;
}
(function() {
this.displayValue = function() {
alert("value = " + this.value);
};
this.changeValue = function(value) {
this.value = value;
};
}).apply(simpleClass);
a = new simpleClass("abcd");
a.changeValue("efgh");
a.displayValue();
</script>
snippet should, at the very least, not yield any errors.
Unfortunately, it does, suggesting my understanding is... limited.
Any ideas as to what's wrong?:
<script>
function simpleClass(value) {
this.value = value;
}
(function() {
this.displayValue = function() {
alert("value = " + this.value);
};
this.changeValue = function(value) {
this.value = value;
};
}).apply(simpleClass);
a = new simpleClass("abcd");
a.changeValue("efgh");
a.displayValue();
</script>