minimal-js
Minimal (564 bytes) js extensions
defClass(name, proto)
shorthand for js classes, returns one-arg constructor, initializing new instance with provided options, new class is also defined globally on window.
var Person = batman = name: 'Batman'; ;;;;;
custom initialization is supported with optional init() method.
var Person = batman = name: 'Bruce Wayne';;
prototype inheritance is still supported.
var Person = Hero = BadGuy = batman = name: 'Batman' joker = name: 'Joker'; ;;
it is possible to define static methods with extend.
var ActiveRecord = User = ; Userall;
returned constructor can be used as mapping function.
var Person = jsonData = name: 'Batman' name: 'Joker' heroes = jsonData; ;;
init() can override returned instance from new.
//TODO: example
data.init wont be called (inheritance).
var BaseModel = User = ;
dot(prop, args...)
returns callback (property getter) suitable for Array.map().
var heroes = name: 'Batman' name: 'Joker' heroNames = heroes; assert;
works well with Array.filter() too.
var users = name: 'Admin' isAdmin: true name: 'Test' admins = users; assert;
for methods, result from their call will be returned.
var heroNames = 'Batman' 'Joker' uppers = heroNames; assert;
any additional arguments are passed to method as expected.
var heroNames = 'Batman' 'Joker' initials = heroNames; assert;
can be also used as a general utility function.
console;
extend(a, b, ...)
extends object with properties from another.
var dest = prop: 'test'; ;;
overrides existing properties.
var dest = prop: 'test'; ;;
always returns first argument.
var a = {} b = {}; ;;
can be used to create shallow copies.
var src = prop: 'test'; assert;
varargs are translated to subsequent recursive calls, nesting from left.
var a = a: 1 b = b: 2 c = c: 3; assert;
extend(a, {}) does nothing to a.
;
extend() throws an error.
try ; assert;catche{}