My Own OOJS

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

I really, really don't like Javascript's Object-Oriented Model.

I propose a model I do like.

Explicit get's and set's

o.has('attr')
o.get('attr')
o.set('attr')
o.del('attr')

With the three above methods, all shared among all object instances, I can do all sorts of wild things.

Basic Types

Basic types can provide other methods:

Callables

If I specify how function calls are made, I can get crazy.

o.call(ordered_args, named_args) -> the result

Booleans

o.true() -> true, false

Numbers

o.number() -> a number

Strings

o.string() -> a string

Typing

o.get('__type__')

This will return the type of the object. This is the thing used to make it.

Lisp-like methods

Methods are registered globally. They list what arguments they expect and what type are expected for each argument.