Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
September 02, 2014, 10:56:14 AM

Pages: [1]   Go Down
  Print  
Author Topic: Inheriting from Date  (Read 1534 times)
auweout
Pong! (the videogame) Master
*****
Offline Offline

Posts: 28


« on: November 10, 2011, 10:22:00 PM »

Is there any way at all to create a new template object that inherits from the built in Date object so as to be able to add new methods to that child object without adding them to the built in Date object? I've tried everything I can think of and as far as I can tell it keeps referencing the Date function instead of the Date object and so doesn't work.
Logged
MrPhil
Senior Moderator
Berserker Poster
*****
Offline Offline

Posts: 5871



« Reply #1 on: April 08, 2013, 05:12:39 AM »

(A bit late on the reply, but maybe this will help someone in the future...)

Javascript is not really an Object Oriented language. It doesn't have true objects and inheritance like you might be used to in something like C++ or Java. Some authors describe it as an "Object Based" language. The short story is that I don't think you can do exactly the kind of inheritance you're trying to do.
Logged

Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-
scanman20
Senior Moderator
Über Jedi
*****
Offline Offline

Posts: 1544



WWW
« Reply #2 on: April 08, 2013, 05:24:11 AM »

Funny you say that because in JavaScript, nearly everything is an object. For reference, check out https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Working_with_Objects.

Couple of excerpts:

"Object everything - In JavaScript, almost everything is an object. All primitive types except null and undefined are treated as objects. They can be assigned properties (assigned properties of some types are not persistent), and they have all characteristics of objects."

"JavaScript is designed on a simple object-based paradigm. An object is a collection of properties, and a property is an association between a name and a value. A value of property can be a function, which is then known as the object's method. In addition to objects that are predefined in the browser, you can define your own objects."
Logged

Even a broken clock is right twice a day.
NotOneBit.com
MCSE - MCSA - MCP
Pages: [1]   Go Up
  Print  
 
Jump to: