- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 11:29 PM
I am creating an extended class, and want to call the parent class's function. How would I do that. I tried the following and failed.
When I run this:
var a = Class.create();
a.prototype = {
initialize: function() {
gs.print('init a');
},
foo: function() {
gs.print('foo a');
},
bar: function() {
gs.print('bar a');
},
type: 'a'
};
var b = Class.create();
b.prototype = Object.extendsObject(a, {
initialize: function() {
//super();
gs.print('init b');
},
foo: function() {
gs.print('foo b');
//super.foo();
},
type: 'b'
});
var c = new b();
c.foo();
c.bar();
I get this:
*** Script: init b
*** Script: foo b
*** Script: bar a
Which is as expected, but I would like to call the parent function twice. Once in the constructor and once in the function, though 'super' does not seem to work. Any ideas?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2017 01:51 AM
Okay, second conslusion. It seems that super is only available from ES6 and SNOW still uses ES5 (in Jakarta).
It seems I fixed the issue by using ParentClass.prototype.myMethod.call(this, arg1, arg2, ...);
So respectively
a.prototype.initialize.call(this);
and
a.prototype.foo.call(this);
I will leave the question open, in case a developer with more experience has more input on this issue.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 11:49 PM
Okay. So it seems that super is only available from ES6 and SNOW still uses ES5 (in Jakarta).
It seems I fixed the issue by using ParentClass.prototype.myMethod();
So respectively
a.prototype.initialize();
and
a.prototype.foo();
I will leave the question open, in case a developer with more experience has more input on this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2017 11:52 PM
Thanks for the info peter, you should document this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2017 01:26 AM
Okay, not there yet. It seems that the functions are called correctly, but onto a different object, because the variables are not correctly manipulated on the current object.
I tried the following:
var a = Class.create();
a.prototype = {
initialize: function() {
gs.print('init a');
this.var1 = 'Hello';
},
foo: function() {
gs.print(this.var1 + ' World');
},
type: 'a'
};
var b = Class.create();
b.prototype = Object.extendsObject(a, {
initialize: function() {
a.prototype.initialize();
gs.print('init b');
},
type: 'b'
});
var c = new b();
c.foo();
And got:
*** Script: init a
*** Script: init b
*** Script: undefined World
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2017 01:51 AM
Okay, second conslusion. It seems that super is only available from ES6 and SNOW still uses ES5 (in Jakarta).
It seems I fixed the issue by using ParentClass.prototype.myMethod.call(this, arg1, arg2, ...);
So respectively
a.prototype.initialize.call(this);
and
a.prototype.foo.call(this);
I will leave the question open, in case a developer with more experience has more input on this issue.