Script Scraper

Pull Data from the Internet into Excel Spreadsheets.

Classes and Objects

Classes and objects are considered the advanced subjects in computer programming, but are also the most useful. Object Orientated programming is the idea where we model concepts in the real world using classes in our computer languages. Doing so allows programmers to build up abstractions which is necessary when dealing with large problem domains.

Objects are easy to create in Javascript.

var person = new function Person(name, sex, age, eyecolor){
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.eyecolor = eyecolor;
};

var oldMan = new Person("John", 'M', 88, "blue");
And we have a object representing an old man with blue eyes. To add functionality to the class we add prototype methods. Here we add a method that will return a description of our Person.
 
Person.prototype.toString = function() {
        var description = "grown up";
        if (this.age > 80) 
                description = "retired";
        if (this.age < 18) 
                description ="young";           
        
        return "I'm a " + description + " " + (this.sex =="M" ? 'man' : 'woman') + " of " + this.age + " years.";
}
We can create two people and display their details.
var oldMan = new Person("Paul", "M", 16, "green");
var youngWoman = new Person("Mary", "F", 88, "blue");

out.println(oldMan.toString());
out.println(youngWoman.toString());
The console displays the result.
>>I'm a young man of 16 years.
>>I'm a retired woman of 88 years.