-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Consider supporting prototype methods #14
Comments
Not something I personally need, but I can see it being useful for many, so PR welcome :) Should be a boolean option that is You might find inspiration in the Bluebird implementation https://github.com/petkaantonov/bluebird/blob/master/src/promisify.js |
Great, thanks! I'll see what I can do. |
@kevinoid I assume we only consider Enumerable and Inherited Enumerable properties. In that case I think it is sufficient to choose |
@schnittstabil I agree, that sounds like the right behavior and implementation to me. Thanks. Feel free to do the PR if you are strongly motivated, I'm not picky about it. Otherwise I should have some time to hammer it out later today. |
Sorry @kevinoid, I do neither see the need for that option nor have much time to implement it. |
This makes it possible to transform objects which are instances of a class without knowing which methods are present on the instance object and which are inherited through the prototype chain. Include/Exclude is handled the same as for non-inherited methods. In addition to transforming inherited methods, when the inherited option is enabled the result object is created with the prototype of the original object so that it behaves the same as the original object for instanceof checks. Fixes sindresorhus#14 Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This makes it possible to transform objects which are instances of a class without knowing which methods are present on the instance object and which are inherited through the prototype chain. Include/Exclude is handled the same as for non-inherited methods. In addition to transforming inherited methods, when the inherited option is enabled the result object is created with the prototype of the original object so that it behaves the same as the original object for instanceof checks. Fixes sindresorhus#14 Changes in v2: - Default-initialize ret to an empty object. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This makes it possible to transform objects which are instances of a class without knowing which methods are present on the instance object and which are inherited through the prototype chain. Include/Exclude is handled the same as for non-inherited methods. In addition to transforming inherited methods, when the inherited option is enabled the result object is created with the prototype of the original object so that it behaves the same as the original object for instanceof checks. Fixes sindresorhus#14 Changes in v2: - Default-initialize ret to an empty object. Changes in v3: - Replace reduction over keys array with a for-in loop. Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This makes it possible to transform objects which are instances of a class without knowing which methods are present on the instance object and which are inherited through the prototype chain. Include/Exclude is handled the same as for non-inherited methods. In addition to transforming inherited methods, when the inherited option is enabled the result object is created with the prototype of the original object so that it behaves the same as the original object for instanceof checks. Fixes sindresorhus#14 Changes in v2: - Default-initialize ret to an empty object. Changes in v3: - Replace reduction over keys array with a for-in loop. Changes in v4: - Rebase on to latest master (ES2015, ava changes, style changes). Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
Any chance you would be willing to consider supporting
pify
-ing the prototypally-inherited methods of passed objects?The main issue that I'm trying to solve is that code such as:
works if the
Car
constructor sets/copies/binds methods tothis
, but not if the methods are inherited viaprototype
. So, unless I've missed something,pify
users must either depend on the implementation ofCar
or roll their own method iteration wrapper forpify
(and/orpify
the prototype, thenpify
any methods set by the constructor).If
pify
-ing inherited methods sounds agreeable but you'd need a PR to consider, I can work one up. I would envision the methods being copied from the prototype to the new target object if a boolean option is set, but alternatives would be fine with me.Thanks for considering,
Kevin
The text was updated successfully, but these errors were encountered: