moldy/moldy — pull request #6 by dervalp (2014-04-23 12:26:46+00:00)
Title: Add a way to extend Prototype, add initial values and try to fix #5

So, I have changed the API to split the creation of the object in 2 parts. An "extend" which configure the "Klass" you want to create and the "create" method which will instantiate the object.

I was trying to do an application using moldy and I quickly needed those 2 features.

Generally, the creation of the "Klass" and the creation of an object is located in 2 different places in the lifetime of an application.

I would personally create and configure all the "Klass" in the initialization of my application. On the other hand, the creation of an object will generally live during a "request" ( if it is a web app).

So now, you can do:

1. Extend the base Moldy

```
var personSchema = {
properties: {
firstname: {
type: 'string',
default: 'David'
},
lastname: 'string',
age: {
type: 'number',
default: 30
}
}
};

var personProto = { fullName: function () { return this.firstname + " " + this.lastName } };

var Person = Moldy.extend('person').schema( personSchema ).proto( personProto );

```

Now that you have defined a type "Person" which extends the Moldy Base Model.

You can create an object of type "Person" like this:

```
var david = Person.create({ lastname: "Tsu" });
david.fullname(); //output "David Tsu"
```

Hope you like it ( I personally like a lot that API )