The input type of the constuctor function of the circuit in this case is an object, therefore, the notation {}.
function Schema (o){ this.user = o.user; this.time = o.time; this.content = o.content; };
An object is just a variable, like a string or a number. That way you can pass it to a function. But instead of creating an object first, the input object in your example is written in a call like this
mySchema = new Schema({user:'john'});
instead:
var myObj = {user:'john'}; mySchema = new Schema(myObj);
The advantage of this method is that you can change your function without changing its signature. Another advantage is that if you have many input parameters, not all of them are required, you do not need to add default values for parameters that you do not use. For example:
var mySchema1 = new Schema({size:25}); var mySchema2 = new Schema({name:'the best schema ever'});
if the function signature is:
function Schema(size,name) {
You will need to call:
var mySchema2 = new Schema(0,'the best schema ever');
Where 0 is the default value for the size. You can imagine that it can be annoying when there are many options.
Michiel Jun 20 '13 at 14:35 2013-06-20 14:35
source share