How to make a chain of methods in javscript?

I have a basic model:
define(function () {
 var model;

 model = function () { 
};

 model.extend = function(props) {
...
}
 // a couple functions

 return model;
})


Specific model:
define(['models'], function (Model) {
 var myModel;

 myModel = Model.extend ({
 // how to make this chain of methods?
 Id: Model.type('number').title('Title 1'),
 Name: Model.type('string').title("Title 2")
})
})


Then I want the method, for example `build` which will return me the object:
define(['myModel'], function (MyModel) {
 var buildedModel = MyModel.build();
})


Method will return the object of the following form:
{
 Id: { type: "number", title: "Title 1" },
 Name: { type: "string", title: "Title 2" } 
}
September 26th 19 at 07:25
1 answer
September 26th 19 at 07:27
Not sure I exactly understand the question. But to be able to implement chain methods, it is necessary that each method returned the object that caused it (already changed).
That is Model.type() returns the Model with the changed type.

Find more questions by tags JavaScript