0
私はJavaScriptの専門家ではなく、ここでどのように既存のオブジェクトを拡張できますか?Javascriptオブジェクトフィーチャーセットを拡張する
HTML:
<li data-brandtarget="Netherlands"><img src="images/netherlands.png" alt="Netherlands">Netherlands</li>
<li data-brandtarget="Netherlands"><img src="images/netherlands.png" alt="Netherlands">Netherlands</li>
JS:私は国を作るしようとしています
MedicareDataSource.prototype.FEATURES_ = new storeLocator.FeatureSet(
// Brand Fetures
new storeLocator.Feature('Aquafleur-YES', 'Aquafleur'),
new storeLocator.Feature('Aquafarm-YES', 'Aquafarm'),
new storeLocator.Feature('Bm_Web-YES', 'Blue Marine'),
// The below mentioned features I want to be added based on a loop
//new storeLocator.Feature('Naamlandnat-Netherlands', 'Netherlands'),
//new storeLocator.Feature('Naamlandnat-Great Britain', 'Great Britain'),
//new storeLocator.Feature('Naamlandnat-France', 'France'),
//new storeLocator.Feature('Naamlandnat-Germany', 'Germany')
);
はダイナミックます。だから私はすべてのリストをループして属性を取得しています。さて、どのように拡張して既存のオブジェクトに新しい機能を追加することができますか?以下は私のアプローチです。
jQuery('.country-options li').each(function(){
var countryName = jQuery(this).attr('data-brandtarget');
MedicareDataSource.prototype.FEATURES_ = new storeLocator.FeatureSet(
// Country Features
new storeLocator.Feature('Naamlandnat-'+ countryName, countryName)
);
});
私は私が推測するので、それは間違っている知っている:私は、既存のオブジェクトを上書きするため、唯一の最後の機能は、オブジェクトにとどまる各ループで何度も何度も新しいオブジェクトを作成しています。
ここで既存のフィーチャセットを上書きせずにフィーチャを拡張する正しい方法は何ですか?
私も試してみました: new
を削除し、ちょうどstoreLocator.FeatureSet(...);
ループ内でそれを維持するが、うまくいきませんでしたで。
感謝を。 –