Last Updated: February 25, 2016
·
1.03K
· ericraio

JavaScript and Io, Two Languages, One OO Concept.

Learning Io helped me better understand JavaScript. Io is a programming language that not very many people are familiar with. Both Io and JavaScript are Prototyped-based programming which is an Object Oriented style where there is no classes. The idea is that you have one base object that you clone from. From the cloned object you insert methods from the surface. Below, I am going to show you two examples of OO in both Io and JavaScript

Here is a very basic implementation of OO in JavaScript

var Animal = function() {
  this.name = function() {
    return 'Jack';
  }

  return this;
}

var Dog = function() {

  this.bark = function() {
    return 'BARK';
  }

  return this;
}

// Dog extends animal
Dog.prototype = new Animal();

// Creating an instance of Dog.
var dog = new Dog();
dog.bark();           // 'BARK'
dog.name();           // 'Jack'

Here is the same code in Io

Animal := Object clone
Animal name := "Jack"

Dog := Animal clone
Dog bark := "Bark"

Dog bark  // "Bark"
Dog name  // "Jack"

I definitely recommend checking out Io and giving it a try. http://iolanguage.org

Also check out the book Seven Languages in Seven Weeks. I find that learning multiple languages can really make an impact on how you program and it can really make you a better programmer in your main language.

3 Responses
Add your response

another language. Nice writing @eric :)

over 1 year ago ·

Try CoffeeScript

over 1 year ago ·

I'll add another endorsement of that book, it's pretty fantastic. Thanks for the reminder of it, I haven't gone through it "properly" and actually run the code samples; I'll be doing that over my winter vacation.

over 1 year ago ·