SailJs, NodeJs methods
I am still learning to understand NodeJs / SailsJs, sorry if they sound too silly, but I cannot google for a better explanation. I've tried looking for node OOP programming but doesn't seem to explain.
Taking the following request code
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(util.inspect(results, true, null))
})
The output will be
{ id: 1,
companyName: 'Wunly Enterprise1',
createdAt: null,
updatedAt: Wed Jul 08 2015 01:43:19 GMT+0800 (SGT) }
But in SailJs I can use the following code to update the post
results.name = "change name";
results.save(function(err,newresult){})
Howcome can I call the save method when I console.log and no such method exists?
+3
source to share
1 answer
console.log in NodeJs does not print inherited methods (like in chrome, ff ...). save is the attribute method that each record inherits.
If you want to print all properties of an object, you can use this solution fooobar.com/questions/26292 / ...
just declare the function
function getAllPropertyNames( obj ) {
var props = [];
do {
props= props.concat(Object.getOwnPropertyNames( obj ));
} while ( obj = Object.getPrototypeOf( obj ) );
return props;
}
And let's implement it in your example
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(getAllPropertyNames(result));
})
+6
source to share