I linked to the anchor where it says that, right to the bottom of the section 4.3. Will people just STOP saying JavaScript was ‘never intended’ to have ‘nothing to do with Java’? They clearly meant JavaScript to be to Java what AWK is to C, at least syntax-wise. I was born one year after JS was conceived (the standard says ‘invented’, invented my ass! Who ‘invents’ a language?) so I am too young to have been around in the early days of web. But it seems like people back then wanted Java to be lingua franca of web, a bit like PostScript in the thread I posted a few hours ago. They named it JavaScript to assure people that it’s the interpreted, scripting form of Java.

Now don’t say ‘JS and Java are like car and carpet’ you will look like an idiot.

Also if you are wondering why I am reading the standard, it serves two purposes. First is, I wanna implement it one day in the future. Second is, I know shit about web scripting and I wanted to make myself a blog and I miserably failed. So I am learning it.

I know nobody asked, but one person might be wondering why someone would do this to himself.

  • abhibeckert@lemmy.world
    link
    fedilink
    arrow-up
    5
    arrow-down
    1
    ·
    edit-2
    9 months ago

    These two code blocks don’t use standard libraries (aside printing output) and have nothing in common. Even output is totally different, since at the time JavaScript did not support text output at all (there was no browser console). They are as close as you can possibly get between the two languages (they’re not really close at all, because in the 90’s it wasn’t possible to define “real” classes in JavaScript, and to this day it’s not possible for a function to have instance variables in Java).

    And as someone who’s been writing JavaScript professionally for 20 years… I assure you it’s full of quirks that still confuse the heck out of me at times. I mean just last week I had a problem with variable scope that took me three hours to figure out what was wrong with the code. I’m sure some people are more familiar with it, but I’m not one of those people… probably because I avoid the language as much as I possibly can and try to make it behave like “any other language” even though it definitely isn’t that.

    Java:

    public class Animal {
        private String name;
    
        public Animal(String name) {
            this.name = name;
        }
    
        public String getName() {
            return this.name;
        }
    }
    
    public class Application {
        public static void main(String[] args) {
            Animal myAnimal = new Animal("Spike");
            System.out.println(myAnimal.getName());
        }
    }
    

    JavaScript:

    function Animal(name) {
        this.name = name;
    }
    
    Animal.prototype.getName = function() {
        return this.name;
    };
    
    var myAnimal = new Animal("Spike");
    alert(myAnimal.getName());