Last active
December 15, 2015 08:39
-
-
Save mizchi/5232813 to your computer and use it in GitHub Desktop.
俺alt.js草案
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###### なんとか言語 | |
trait Greedable { | |
name: String | |
greeding() { | |
console.log "hello" name | |
} | |
} | |
struct Person { | |
name: String | |
age : Int | |
} | |
struct Worker < Person : Greedable { | |
work: (int) -> void | |
} | |
worker = Worker { | |
name: "mizchi" | |
age : 24 | |
} | |
worker.greeding #=> hello mizchi | |
##################### コンパイル | |
var | |
__hasProp = {}.hasOwnProperty, | |
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | |
__use = function(Class){ var n = 1; while(Trait = arguments[n++]){ for(var key in Trait) Class.prototype[key] = Trait[key]}}; | |
var Greedable = { | |
greeding: function(){ console.log("hello", name)} | |
}; | |
var Person = (function(){ | |
function Person(__obj){ | |
this.name = __obj.name; | |
this.age = __obj.age; | |
} | |
return Person; | |
})(); | |
var Worker = (function(_super) { | |
__extends(Worker, _super); | |
__use(Worker, [Greedable]); | |
function Worker() { | |
return Worker.__super__.constructor.apply(this, arguments); | |
} | |
return Worker; | |
})(Person); | |
worker = new Worker({ | |
name: "mizchi", | |
age: 24 | |
}); | |
worker.greeding() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment