I want to extend the JSDataSet class (object) with prototype to define a function append ( jsDataSet ). How can I realize that?
Here is an example with the built in Error class.
function MyError(message){
this.message = message;
}
MyError.prototype = new Error();
Then later…
throw new MyError("Hello world!");
Thanks, Scott!
goldcougar:
Here is an example with the built in Error class.function MyError(message){
this.message = message;
}
MyError.prototype = new Error();
If I try:
MyError.prototype.getMyErrorMessage = function () {
return this.message;
}
I get this: “The property getMyErrorMessage is undefined for the javascript type Object” warning and if I create an object like:
var myErr = new MyError('my error' );
and call the method:
myErr.getMyErrorMessage();
I get the following error:
=>forms.boss_char_charterfaktura_base_dtl.myErr.getMyErrorMessage();
org.mozilla.javascript.EcmaError: TypeError: Cannot find function getMyErrorMessage in object [object Object]. (internal_anon#1)
How can I add my own functions / properties to the MyError ‘class’?
what is the full js file that you do when you do this:
MyError.prototype.getMyErrorMessage = function () {
return this.message;
}
it must me something like this;
var initializer = function() {
MyError.prototype.getMyErrorMessage = function () {
return this.message;
}
}();
function MyError(message){
this.message = message;
}
function tst() {
var x = new MyError("test");
x.getMyErrorMessage ();
}