node.js - SailJs, NodeJs methods -
i'm still learning understand nodejs/sailsjs, sorry if these sound stupid can't seem search google better explanation. have tried searching node oop programming doesn't seems explain.
taking following query code
company.findone({'id':req.param('id')}).then(function(results){ console.log(util.inspect(results, true, null)) })
the output
{ id: 1, companyname: 'wunly enterprise1', createdat: null, updatedat: wed jul 08 2015 01:43:19 gmt+0800 (sgt) }
but in sailjs, can use following code update record
results.name = "change name"; results.save(function(err,newresult){})
howcome able call save method when console.log , there no such method exists??
console.log in nodejs doesn't print inherited methods (like in chrome, ff...). save attribute method every record inherits.
if want print properties of object, can use solution https://stackoverflow.com/a/8024294/1334743
just declare function
function getallpropertynames( obj ) { var props = []; { props= props.concat(object.getownpropertynames( obj )); } while ( obj = object.getprototypeof( obj ) ); return props; }
and implement in example
company.findone({'id':req.param('id')}).then(function(results){ console.log(getallpropertynames(result)); })
Comments
Post a Comment