I was actually curious about this in Ruby as well, since Ruby also doesn't
have the Smalltalk message syntax.

I figure that the magic behind it is that Smalltalk takes strings like "dict
at: 'foo' put: 'bar'" and evaluates them into a JavaScript equivalent of
"dict['at:put:']('foo', 'bar')".

Basically, my proof of concept(I cheated with regex to cut time):

'use strict';

var Dictionary = function Dictionary() {
    this.dict = {};
Dictionary.prototype['at:put:'] = function(index, value) {
    this.dict[index] = value;
Object.defineProperty(Dictionary, 'new', {
    get: function () {
        return new this;

function st_eval(str) {
    var x = str.match(/(dict)\s+(at):\s+'(foo)'\s+(put):\s+'(bar)'/);
    var target = x[1];
    var callName = x[2] + ':' + x[4] + ':';
    var argv = [x[3], x[5]];
    var realTarget = eval(target);
    realTarget[callName].apply(realTarget, argv);

var dict = Dictionary.new;
//dict['at:put:']('foo', 'bar');
st_eval("dict at: 'foo' put: 'bar'");

View this message in context: 
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply via email to