Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending Vinyl still have build in properties #144

Closed
juliet-zhu opened this issue Apr 18, 2019 · 3 comments
Closed

Extending Vinyl still have build in properties #144

juliet-zhu opened this issue Apr 18, 2019 · 3 comments

Comments

@juliet-zhu
Copy link

juliet-zhu commented Apr 18, 2019

Hi, in README.md [https://github.com/gulpjs/vinyl#extending-vinyl]

var Vinyl = require('vinyl');

var 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;
  }
}
var superIns = new SuperFile();
var superInsCopy = superIns.clone();
console.log(superInsCopy.foo);

From my understanding, foo or _foo should not be in superIns and superInsCopy instacnes, but I still can query them.

@phated
Copy link
Member

phated commented Apr 19, 2019

The documentation is phrased incorrectly. If something is set in the constructor, it'll be set on the clone because this.constructor() is called at https://github.com/gulpjs/vinyl/blob/master/index.js#L123 and anything on the prototype is also going to be there for the same reasons. The isCustomProp stuff is only to prevent someone from doing new Vinyl({ foo: "something" }) and overwrite a prop you assigned internally.

@juliet-zhu
Copy link
Author

Much clear now. Thanks a lot.

@phated
Copy link
Member

phated commented Apr 22, 2019

Glad that helped. I've updated the docs with my above explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants