Node.js
スクレイパーによって構築されているかなり単純な javascript/jquery オブジェクトがあります。すべてが正常に機能します (obj.prod_name_select
対応するものは jquery セレクターを返し、ノードで問題なく解析しています)。
オブジェクトは次のとおりです。
var product = {
name : $(obj.prod_name_select).text(),
systemName : function(){
return product.name.replace(/\s+/g, ' ');
},
gender : obj.gender,
infoLink : link,
designer : $(obj.label_name_select).first().text(),
description : function(){
var text = $(obj.description).each(function() {
var content = $(this).contents();
$(this).replaceWith(content);
});
return text;
},
price : $(obj.price_select).first().text(),
store : obj.store,
category : obj.general_cat,
spec_cat : obj.spec_cat
}
console.log(product);
これをノードで実行すると、関数によって設定されるプロパティを除いて、すべて正常に動作します。これら[FUNCTION]
はノードに戻ります。コンソールからのログは次のとおりです。
{ name: 'BAGGY PANTS!T',
systemName: [Function],
gender: 'men',
infoLink: 'http://www.hereisthecorrecturl.com',
designer: 'Fancy Designer',
description: [Function],
price: '$180.00',
store: 'Correct Store Name',
category: 'Correct Category',
spec_cat: 'Correct Category' }
これは非同期の問題ですか? プロパティ関数が実行される前に console.log が発生しているようです。これを解決する最善の方法は何ですか?