Chr*_*Sim 3 oop prototype node.js sails.js
我还在学习理解NodeJs/SailsJs,对不起,如果这些听起来太愚蠢但我似乎无法搜索谷歌以获得更好的解释.我试过寻找节点OOP编程,但似乎没有解释.
采用以下查询代码
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(util.inspect(results, true, null))
})
Run Code Online (Sandbox Code Playgroud)
输出将是
{ id: 1,
companyName: 'Wunly Enterprise1',
createdAt: null,
updatedAt: Wed Jul 08 2015 01:43:19 GMT+0800 (SGT) }
Run Code Online (Sandbox Code Playgroud)
但是在SailJs中,我可以使用以下代码来更新记录
results.name = "change name";
results.save(function(err,newresult){})
Run Code Online (Sandbox Code Playgroud)
如果我在console.log中调用save方法并且没有这样的方法存在?
小智 6
NodeJs中的console.log不会打印继承的方法(如chrome,ff ...).save是每个记录继承的属性方法.
如果要打印对象的所有属性,可以使用此解决方案 /sf/answers/561700611/
只是声明功能
function getAllPropertyNames( obj ) {
var props = [];
do {
props= props.concat(Object.getOwnPropertyNames( obj ));
} while ( obj = Object.getPrototypeOf( obj ) );
return props;
}
Run Code Online (Sandbox Code Playgroud)
并在您的示例中实现它
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(getAllPropertyNames(result));
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |