ympbyc / LittleSmallscript

JavaScript with Smalltalk's syntax

Home Page:http://ympbyc.github.io/LittleSmallscript/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Proposal for new class header syntax

ympbyc opened this issue · comments

Proposal:

Snake := Class extend: Animal variables: #(#name #color).

Sample implementation:

Class = {};
Class.extendvariables = function (Parent, varArr) {
  var Child;
  Child = function () {
    var _this = this;
    varArr.forEach(function (v) {
      _this[v] = null;
    });
    if (this.init) {this.init.apply(this, arguments)}
  };
  Child.prototype = new Parent();
  return Child;
};

How about
"Snake := Animal subclass variables: #(name color)."
or
"Snake := Animal extend variables: #(name color)."
?

I like your one better! It's kind of like an internal DSL.

Function.prototype.subclass = function () {
  var This = this;
  return {
    variables: function (varArr) {
      var Child;
      Child  = function () {
        var _this = this;
        varArr.forEach(function (v) {
          _this[v] = null;
        });
      };
      Child.prototype = new This();
      return Child;
    }
  };
};