Nathan-Wall / proto

A programming language derived from JavaScript which emphasizes prototypes, integrity, and syntax.
Other
12 stars 1 forks source link

Syntactic Prototypes #91

Open Nathan-Wall opened 10 years ago

Nathan-Wall commented 10 years ago

Proposal

Currently prototypes are declared by stating a base class and mixing in properties.

sym @employees;
var Manager = like Employee := #{
    @employees: nil,
    init: fn() :{
        this::Employee();
        this.@employees = [ ];
    },
    addEmployee: fn(employee) :{
        this.@employees.push(employee);
    }
};

While it's nice the way various syntactic forms come together to produce an easily readable prototype definition without the need for special syntax, we could still stand to gain some by adding special syntax.

proto Manager like Employee {
    @employees = [ ];
    fn init() :{
        super();
    }
    fn addEmployee(employee) :{
        this.@employees.push(employee);
    }
}

Pros