Javascript inheritance misbehaviour
NickName:user49126 Ask DateTime:2011-10-19T21:33:49

Javascript inheritance misbehaviour

I have some js code here link deleted

If you open your js console and you'll run this code snipet

var r = new TempPopupForm("xxx");
r.create();

an error will appear

TypeError: this.init is not a function

this error is saying there is no init method implemented on this object.

But that's not true.As you can see in the code below the init method is declared.

TempPopupForm.prototype = new PopupForm();
TempPopupForm.prototype.constructor = TempPopupForm;
TempPopupForm.superclass = PopupForm.prototype;

function TempPopupForm(name) {
     this.init(name);
}
TempPopupForm.prototype.init = function(name) {
     TempPopupForm.superclass.init.call(this, name);
};

I guess something is wrong with the inheritance definition,but I can not figure out what it is.

BTW There are some third party dependencies.

EDIT

I was following this article and where the funcs are ordered like I have. The order actually works on the other classes, but not on this one. http://www.kevlindev.com/tutorials/javascript/inheritance/inheritance10.htm

Copyright Notice:Content Author:「user49126」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7822112/javascript-inheritance-misbehaviour

More about “Javascript inheritance misbehaviour” related questions

Javascript inheritance misbehaviour

I have some js code here link deleted If you open your js console and you'll run this code snipet var r = new TempPopupForm("xxx"); r.create(); an error will appear TypeError: this.init is not a

Show Detail

Prison Architect obj.Misbehaviour

I´am currently working on a mod that causes guards to call backup when they see a misbehaving prisoner. This is what I got on pastebin.com : http://pastebin.com/322dRw3s The part that doesnt work is "

Show Detail

Class Inheritance in Javascript

I am wondering how to simulate Class Inheritance in JavaScript. I know class doesn't apply to JavaScript, the way we use is Functions to create objects and do the inheritance things through Prototype

Show Detail

Javascript inheritance

I'm trying a few different approaches to Javascript inheritance at the moment. I have the following code: ('borrowed' from http://www.kevlindev.com/tutorials/javascript/inheritance/index.htm) KV...

Show Detail

JavaScript inheritance

Douglas Crockford seems to like the following inheritance approach: if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; ...

Show Detail

Javascript Privilege Function Inheritance

I have spent the past few weeks doing a ton of research on Javascript inheritance. Firstly, I want to say that I am NOT trying to implement class-based inheritance in Javascript, however, I am tryi...

Show Detail

What is differential inheritance in JavaScript?

This answer on Object.create() method in JavaScript in SO talks about differential inheritance. It goes on to say this : This methods allows you to easily implement differential inheritance, w...

Show Detail

Implement multiple inheritance in Javascript

I have observed that through the use of "prototype" property in Javascript (and indirectly setting up the prototype chain), one can implement multi-level inheritance in JavaScript. But is it possib...

Show Detail

javascript inheritance

I know there is a lot of similar questions are tons of great answers to this. I tried to look at the classical inheritance methods, or those closure methods etc. Somehow I consider they are more or...

Show Detail

Javascript inheritance implementation question

In his sitepoint article about javascript inheritance, Harry Fuecks explains a way of implementing inheritance as follows: function copyPrototype(descendant, parent) { var sConstructor = p...

Show Detail