So I made that language generator I was thinking of! You’ll get a new language every time you refresh the page. It’s a bit…inelegant, but sometimes it actually comes up with something interesting and theoretically usable! Sometimes you’ll get a randomly generated set of tenses, too. There’s even a chance you’ll get some clicks and/or gutterals/stops as letters, too!

The dictionary at the bottom is mostly a test for creating many different completely unique words. There are no definitions yet. If I feel up to it someday, I may make definition lists to match up to words, but that would take a WHOLE lot of effort. I also started making sample sentences, but I remembered that prefixes and suffixes for different cases would be really hard to determine and add correctly the way it’s set up at the moment.

Anyway, maybe this could be useful to you! Probably not though. I had fun making it at least, and it sometimes makes some interesting results. Let me know if there’s any other general information that I forgot about that’s useful to know for a language and I’ll look into adding it in! :)

Recently I had a dream in which I set homework assignments for Ernest Hemingway and 24 other literary luminaries. Each author received one of five tasks—common coding problems, mostly mathematical—which they were to solve using JavaScript. Naturally this was all too good to keep to myself so I turned their solutions into a book—If Hemingway…

Javascript Fun

I was playing around with JavaScript sort of toying with how “jank” it is stuff like

",,," == new Array(4) 

will return true and things of that nature. when I realized I could do this

[].uhh = function () { return "uh"; }

now that wont really do anything but take a look at that line for a moment, It gives you the impression that something is terribly terribly wrong so I don’t know if you’ll find this interesting or not but I started thinking, well why is that the case and I realized two things, it’s 1 how objects are treated and 2 the fact that functions are first class citizens. The reason this works is because JavaScript treats everything as a hash-y kind of object so [1,2,3,4] really isn’t an array of 1 2 3 4 but really an object with keys 1 2 3 4 so we can define objects and then add attributes to them as we please

var a =  new Date();
a.thisisanextraneousattribute = "hi i'm an extraneous attribute";

is totally valid and as you can imagine if I look at that attribute it will give me back my string. well really I can store anything in there, I can store a function if I wanted to because functions are first class citizens I could have just as easily said this

a.thisisanextraneousfunction = function ()  { return "hi I'm an extraneous function"; }

and to get the string we would just have to invoke it.

a.thisisanextraneousfunction ()

will give us our string. So that’s all neat and nice but doesn’t seem quite as jarring as this

[].uhh = function () { return "uh"; }

well what that’s doing is taking [] which creates an object with no keys, adds an attribute to that stores a function and disappears into the ether because we didn’t save it anywhere. but if you’d like to keep it you can just say

var a = [].uhh = function () { return "uh"; }

and like magic we can call

a.uhh() 

and get our string.

Cheers.

Multiple Inheritance In JavaScript

Just like all other Object Orientation strategies, JavaScript can implement multiple inheritance. There are many strategies to do this, but I think it is easiest with functional inheritance. Here are the parents:

var Shape = function(preSelf) {
    var self = preSelf || {};

    self.type = 'shape';

    self.sayType = function() {
        console.log(self.type);
    };

    return self;
};

var Position = function(preSelf) {
    var self = preSelf || {};

    self.x = 0;
    self.y = 0;
    self.sayPosition = function() {
        console.log(self.x + ':' + self.y);
    }

    return self;
};

var shape = Shape();
shape.sayType();// shape

var position = Position();
position.sayPosition();// 0:0

The passed in argument will be used to provide objects to inherit from (If I wanted to use constructor arguments, I would use a seperate function like init()). Since multiple inheritance just means a child will have properties of more than one parent, it is simplist to do this in a chain. So all that needs to be done is to define a simple inheritance chain:

var CenterCircle = function(preSelf) {
    var self = preSelf || {};

    self.type = 'circle';
    self.x = 6;
    self.y = 7;

    return self;
};

var centerCircle = CenterCircle(Shape(Position()));
centerCircle.sayType();// circle
centerCircle.sayPosition();// 6:7

The brackets can get a little messy when using lots of classes, so a utility function will make things cleaner:

var create = function() {
    var objects = Array.prototype.slice.call(arguments),
        lastObj = objects.slice(-1)[0]();
    for (var i = objects.length - 2; i >= 0; i -= 1) {
        lastObj = objects[i](lastObj);
    }

    return lastObj;
};

var centerCircle = create(CenterCircle, Shape, Position);
centerCircle.sayType();// circle
centerCircle.sayPosition();// 6:7

Github Location: https://github.com/Jacob-Friesen/obscurejs/blob/master/2014/multipleInheritance.js

Text
Photo
Quote
Link
Chat
Audio
Video