pdu74w
Last Updated: February 25, 2016
·
712
· ericraio
69bdacd70dafc570b4d2cc1e670b1968

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.

Say Thanks
Respond

3 Responses
Add your response

11347
06237052745686cba3fcb34d056d3cad

another language. Nice writing @eric :)

over 1 year ago ·
11411
5a4ae49890c55068119f06451cb21a8c

Try CoffeeScript

over 1 year ago ·
11451
Img  uv6opa

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 ·