mercredi 12 août 2015

Can you explain the reflection in javascript in EC6 standard with example I give?

I just find the javascript can do some reflection in standard EC6. (http://ift.tt/1OcKO9U)

I wonder whether or not can do reflect in user defined objects and put it on REST service?

For example, my class is:

var User = Waterline.Collection.extend({

identity: 'user',
connection: 'myLocalDisk',

attributes: {

  first_name: 'string',
  last_name: 'string'
}
name: function(){
     return this.attributes.first_name+" "+this.attributes.last_name;
}
});

var Pet = Waterline.Collection.extend({

identity: 'pet',
connection: 'myLocalMySql',

attributes: {
   name: 'string',
   breed: 'string'
}
somename: function(){
    return something;
}
});

This is comes from: http://ift.tt/1DM0FvV

I want to implement REST api for express framework like:

http://loalhost:3000/api/?class=ClassName&method=function&filter=json_filter

for the user example:

http://loalhost:3000/api/?class=User&method=name&filter={"first_name":"John"}

Then there will be a json files with list of users name "John" with give out. like:

{"users":[{"name": "John Smith"},{"name":"John Maylar"},{"name":"John Hakinson"}],
 "stat": "OK",
  "code":200
 }

Of course the class can modify, for this case it can be User or Pet.

Does javascript reflection can fulfill the rest service like this and how to do it? can you give me a similar example about this?





Aucun commentaire:

Enregistrer un commentaire