Wrox Programmer Forums
|
BOOK: JavaScript 24-Hour Trainer
This is the forum to discuss the Wrox book JavaScript 24-Hour Trainer Jeremy McPeak; ISBN: 978-0-470-64783-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: JavaScript 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 30th, 2012, 11:27 AM
Authorized User
 
Join Date: Aug 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default data type vs class

I've read that JavaScript doesn't have classes. Yet aren't all object instances of a class? JavaScript does have "data types" and the book says objects are instances of data types and talks about creating custom data types. So is a data type just the JavaScript word for a class?
 
Old January 7th, 2013, 11:39 AM
jmcpeak's Avatar
Wrox Author
 
Join Date: Nov 2005
Posts: 87
Thanks: 0
Thanked 18 Times in 17 Posts
Default

Howdy, Econophil. Apologies for the late response.

There are different types of object-oriented languages. The most common are class-based OO languages (C#, C++, Java, etc). A programmer defines a class and creates instances of that class. So in class-based languages, yes, every object is an instance of a class.

JavaScript is a prototype-based language. It doesn't have classes; instead, objects are created from other objects. What we call data types (or reference types, to be more accurate) are nothing more than a function (which is an object) that is called with the new operator.

Data type (or reference type) is the logical equivalent of the concept of class, but they are two different things.

JavaScript is getting a class construct in the future, but it isn't a true class. It's syntactic sugar for the constructor and prototype code that we write today.





Similar Threads
Thread Thread Starter Forum Replies Last Post
he conversion of a char data type to a datetime data type resulted in an out-of-range adamhw Classic ASP Basics 3 December 23rd, 2009 07:18 AM
Question about value class type saadli BOOK: Ivor Horton's Beginning Visual C++ 2008 ISBN: 978-0-470-22590-5 4 December 3rd, 2008 10:15 PM
Class Cannot be Pulic in This Type of Prj BrianWren Pro VB 6 3 May 1st, 2007 04:07 PM
Data Type error but it is the correct type Mitch SQL Server 2000 2 March 19th, 2004 11:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.