Skip to content

Commit

Permalink
Better comments and parameter names.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Feb 2, 2021
1 parent 2de5579 commit 7895e15
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import { Observable } from "zen-observable/esm.js";
// Observable.apply methods with an implementation that calls
// Reflect.construct instead, when available.

Observable.call = function (obs, sub) {
return construct(this, obs, sub);
Observable.call = function (instance, subscriber) {
// Since Observable.call is a static method, 'this' will typically be the
// Observable constructor function, though it could be a subclass of the
// Observable constructor, which is why we don't just hard-code it here.
return construct(this, instance, subscriber);
};

Observable.apply = function (obs, args) {
return construct(this, obs, args[0]);
Observable.apply = function (instance, args) {
return construct(this, instance, args[0]);
};

function construct(Super, self, subscriber) {
function construct(Super, instance, subscriber) {
return typeof Reflect === 'object'
? Reflect.construct(Super, [subscriber], self.constructor)
: Function.prototype.call.call(Super, self, subscriber) || self;
? Reflect.construct(Super, [subscriber], instance.constructor)
: Function.prototype.call.call(Super, instance, subscriber) || instance;
}

export { Observable }

0 comments on commit 7895e15

Please sign in to comment.