General Question

rchamorro's avatar

How to inherit a Javascript class?

Asked by rchamorro (13 points ) December 27th, 2011

I want to use object oriented programming with Javascript. How can I create an object an inherit from it to override some methods?

Observing members: 0 Composing members: 0

4 Answers

MrItty's avatar

There is no such thing as classes or object-oriented programming when it come to Javascript.

Are you sure you didn’t mean Java?

Java is a full programming language, developed by Sun. Javascript is a scripting language that runs in your webbrowser, used to do thing like change the background color when you hover your mouse over a certain image.

rchamorro's avatar

Yes, I am quite sure that It’s javascript what I am talking about.

There is something called prototype that I have seen in javascript code, and also namespaces, but I don’t know the exact implementation.

jaytkay's avatar

Hi, @rchamorro, welcome to Fluther!

A couple of different possibilities for “prototype”.

1)
The prototype object of JavaScript
The prototype object of JavaScript, introduced starting in JavaScript 1.1, is a prebuilt object that simplifies the process of adding custom properties/ methods to all instances of an object.

2)
Prototype
Prototype is a JavaScript Framework that aims to ease development of dynamic web applications. Featuring a unique, easy-to-use toolkit for class-driven development and the nicest Ajax library around…

Zaku's avatar

Actually, JavaScript does have classes and OOP. @MrItty was incorrect above.

There is a quick answer to the question here.

Also interesting is the short web page article ’’Classical Inheritance in JavaScript’’ which shows a nice system for working with classes.

There are plenty of articles available via a Google search (for “javascript class inheritance” for example).

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther