確定一個(gè)屬性是否由 Vinyl 在內(nèi)部進(jìn)行管理。Vinyl 在構(gòu)造函數(shù)中設(shè)置值或在 clone() 實(shí)例方法中復(fù)制屬性時(shí)使用。
這種方法在擴(kuò)展 Vinyl 類時(shí)很有用。詳情參見下文:擴(kuò)展 Vinyl。
const Vinyl = require('vinyl');
Vinyl.isCustomProp('sourceMap') === true;
Vinyl.isCustomProp('path') === false;
Vinyl.isCustomProp(property)
參數(shù) | 類型 | 注解 |
---|---|---|
property | string | 要檢查的屬性名。 |
如果屬性不是內(nèi)部管理的,則為 True。
當(dāng)在內(nèi)部管理自定義屬性時(shí),必須擴(kuò)展靜態(tài) isCustomProp 方法,并在查詢其中一個(gè)自定義屬性時(shí)返回 false。
const Vinyl = require('vinyl');
const builtInProps = ['foo', '_foo'];
class SuperFile extends Vinyl {
constructor(options) {
super(options);
this._foo = 'example internal read-only value';
}
get foo() {
return this._foo;
}
static isCustomProp(name) {
return super.isCustomProp(name) && builtInProps.indexOf(name) === -1;
}
}
在上面的例子中,foo 和 _foo 在克隆或?qū)?nbsp;options 傳遞給 new SuperFile(options) 時(shí)不會(huì)分配給新對(duì)象。
如果您的自定義屬性或邏輯在克隆期間需要特殊處理,請(qǐng)?jiān)跀U(kuò)展 Vinyl 時(shí)覆蓋 clone 方法。
更多建議: