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.
Written by Eric Raio
Related protips
3 Responses
another language. Nice writing @eric :)
Try CoffeeScript
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.