Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript 2.0 classes

I'm reading a book "How to Do Everything with JavaScript" and I'm currently learning how to define classes. The book says there are 2 ways. first using functions in javascript 1.x. second, using class in javascript 2.0.

what I'm trying is:

class Car {
    var Make : String;
    var Model : String;
    var Year : Integer;
    var Color : String;
    var FullName : String;

    function Car (make, model, year, color) {
        this.Make = make;
        this.Model = model;
        this.Year = year;
        this.Color = color;
        this.FullName = this.Year + " " + "<b>" + this.Make + "</b> " + this.Model;
    }
}

var mySUV = new Car("Toyota", "4Runner SR5",2001, "Thundercloud");
document.write ("I drive a " + mySUV.FullName);

The code is not working when I'm trying to run it. I use komodo editor to develop and when I define a class like I mentioned before, It gives me a warning "strict warning: class is a reserved identifier".

Is there something wrong with the code? Thanks in advance for any help.

like image 409
codemaker Avatar asked Dec 13 '09 12:12

codemaker


1 Answers

JavaScript 2.0 aka ECMAScript 4 was abandoned in 2008, before it was ever released. There will never be a class-based version of ECMAScript. Which is a good thing.

like image 141
Jörg W Mittag Avatar answered Sep 23 '22 22:09

Jörg W Mittag