Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

When using object.extendObject, how do you call the parent initialize function?

Community Alums
Not applicable

This seams to work:

 

 

var Parent = Class.create();
Parent.prototype = {
    initialize: function(a) {
		this.a = a;
		this.b = "B";
		gs.info("parent initialize, a = " + this.a + ", b = " + this.b );
    },
    type: 'Parent',
	doIt: function() { gs.log("Parent: Do IT"); },
	sayHello: function() { gs.log("Hello"); }
	,
};



var Child = Class.create();
Child.prototype = Object.extendsObject(Parent, {
    initialize: function() {
		Parent.prototype.initialize.call(this, 3);
		this.a = 5;
		gs.info("child initialize, a = " + this.a + ", b = " + this.b );
    },

    type: 'Child',
	doIt: function() { gs.log("Child: Do IT"); }
});

var c = new Child();
c.doIt();
c.sayHello();

 

 

0 REPLIES 0