Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery class inheritance

Tags:

var A=function(){ };  $.extend(A.prototype, {     init:function(){         alert('A init');     } }); var B=function(){  };  $.extend(B.prototype,A.prototype,{     init:function(){         alert('B init');     } }); var p=new A(); p.init(); var x=new B(); x.init(); 

is the above the best way to create class and inheritance in jQuery? In B's init how do I invoke parent's init (similar to super.init() in OO languages)?

like image 419
user121196 Avatar asked Jul 02 '09 17:07

user121196


People also ask

What is class inheritance in JavaScript?

Inheritance enables you to define a class that takes all the functionality from a parent class and allows you to add more. Using class inheritance, a class can inherit all the methods and properties of another class. Inheritance is a useful feature that allows code reusability.

Does JavaScript support class like inheritance?

JavaScript is a bit confusing for developers experienced in class-based languages (like Java or C++), as it is dynamic and does not have static types. When it comes to inheritance, JavaScript only has one construct: objects. Each object has a private property which holds a link to another object called its prototype.

What is inherited class?

An inherited class is known as Sub Class or Derived Class. Sub Class inherits the properties or characteristics from Base Class, also popularly known as Super class. In the programming world, Sub Class is also referred to as a child class, whereas the superclass is referred to as parent class.

How do you inherit from a class A into a class B in ES6?

Inheriting from two classes can be done by creating a parent object as a combination of two parent prototypes. The syntax for subclassing makes it possible to do that in the declaration, since the right-hand side of the extends clause can be any expression.


1 Answers

For OO, it's best to look outside jQuery. jQuery is based on collections returned by selectors.

If you want classes, some choices are Base2, Joose, and JS.Class.

like image 182
Nosredna Avatar answered Nov 30 '22 03:11

Nosredna