Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract Functions #84

Open
alongubkin opened this issue Nov 26, 2014 · 4 comments
Open

Abstract Functions #84

alongubkin opened this issue Nov 26, 2014 · 4 comments

Comments

@alongubkin
Copy link
Owner

The abstract modifier indicates that a function has a missing or incomplete implementation. Useful for inheritance.

abstract fn Animal() {
}

fn Snake() extends Animal() {
}

var snake = new Snake(); // ok
var animal = new Animal(); // error - Animal is abstract
@alongubkin
Copy link
Owner Author

Implementation:

function Animal() {
  if (!this.__extending) {
    throw "cannot create a new instance of Animal because it is abstract.";
  }
}

function Snake() {
  this.__extending = true;
  Animal.call(this);
}

Snake.prototype = Object.create(Animal);

var snake = new Snake(); // ok
var animal = new Animal(); // error - Animal is abstract

@zekesonxx
Copy link
Contributor

This, while a good solution, is adding runtime code, which is bad.

I'm beginning to think that we need a compiler flag to specify if it's a production or development build, and only put these kinds of things in production.

Also, line 3 should be throw new Error("Cannot create a new instance of Animal because it is abstract.");

@Namek
Copy link
Collaborator

Namek commented Nov 29, 2014

I would put runtime checks only in development build. Production has to be fast.

@Namek
Copy link
Collaborator

Namek commented Nov 30, 2014

#89: Proposal: Split developer/production compilation modes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants