Skip to content

Instantly share code, notes, and snippets.

@Havvy
Last active December 18, 2015 20:49
Show Gist options
  • Save Havvy/5843241 to your computer and use it in GitHub Desktop.
Save Havvy/5843241 to your computer and use it in GitHub Desktop.
// self
// [[call]]
// [[prototype]]
// Mixins
let o = {
[[prototype]]: [Function.prototype, Havvy.Fn.prototype]
[[call]]: function (key) { return self.property[key]; },
property : {
get count : function () {
self(1)._count += 1;
return self(1)._count;
},
}
_count : 0
};
o('property'); // 1

JS Wishes

  • Remove labels. They clutter the syntax for no real gain compared to what PHP did.
  • Replace with break and continue statements taking an optional positive integer (default 1), breaking that many loops out.
  • Match statement (See match.js)
  • [[call]] special property in object literal syntax.
  • [[prototype]] special property in object literal syntax.
  • 'self' lexical variable that refers to current object.
  • 'self(integer n)' lexical function that refers to the nth highest object literal. This looks ugly, but that's intentional. Note that the integer passed must be a literal integer.
  • Mixins via the [[prototype]] property being an array. First go through the prototype chain of the first object in the array. If not found, go through the second. Ect. ect. Until the end. If not found, the key is empty, and return undefined.

Additional Functions

  • arraylike(v) -> true iff 'length' in v and v.length is numeric.
  • callable(v) -> true iff 'v's [[call]] property is not null.
// No fallthrough.
// Error if no match.
// default matches anything.
// Inside the match, self binds to the value being matched.
this.trigger = match (typeof config) {
"string" => config,
"object" where typeof config.trigger === "string" => config.trigger,
default => '!'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment