What is the proper way of creating an inheritance structure in neko? Do
you clone the prototype of a type, add to it, and assign it to the
inherited type? Or is there some other language construct for achieving
this?
Hi Jeremy,
You need to use prototype chaining for inheritance.
Here's an example :
// class A { function A() { } function foo() { } }
// creates class object
A = $new(null);
// create prototype
A.prototype = $new(null);
A.prototype.foo = function() { };
// creates an instance of A
newA = function() {
return $new(A.prototype);
}
// class B extends A { }
// creates class object
B = $new(null);
// create prototype
B.prototype = $new(null);
// set inheritance
$objsetproto(B.prototype,A.prototype);
// creates an instance of B
newB = function() {
return $new(B.prototype);
}
Neko looks awesome, easy to extend, and insanely fast. What a great
idea! Kudos to the developers.
You're welcome :)
Nicolas
--
Neko : One VM to run them all
(http://nekovm.org)