Web Hosting Forum | Lunarpages

Author Topic: Inheriting from Date  (Read 3291 times)

Offline auweout

  • Pong! (the videogame) Master
  • *****
  • Posts: 28
Inheriting from Date
« 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.

Offline MrPhil

  • Senior Moderator
  • Berserker Poster
  • *****
  • Posts: 6225
Re: Inheriting from Date
« 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.
Visit My Site

E-mail Me
  
-= From the ashes shall rise a sooty tern =-

Offline scanman20

  • Senior Moderator
  • Über Jedi
  • *****
  • Posts: 1549
    • http://www.notonebit.com
Re: Inheriting from Date
« 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."
Even a broken clock is right twice a day.
NotOneBit.com
MCSE - MCSA - MCP (<- unused since 2006!)

 

Share |