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

Not a function errors... fn() not a valid function on non-jQuery? #143

Open
dovy opened this issue Nov 19, 2015 · 3 comments
Open

Not a function errors... fn() not a valid function on non-jQuery? #143

dovy opened this issue Nov 19, 2015 · 3 comments
Labels

Comments

@dovy
Copy link
Contributor

dovy commented Nov 19, 2015

@justincy @jimmyz

I've been scratching my head for a while on this. Finally found a stack-trace for this. In my environment I am using Angular w/o any jQuery. In my compressed file, you can see the stack trace here:
https://cloudup.com/cYEL-fFQe9O
Here's an expanded code block:

            f.prototype.setTimer = function(a, b, c) {
                return c && this.settings.clearTimeout(c),
                this.settings.setTimeout(function() {
                    a()
                }
                , b)
            }
            ,
            f.prototype.setAccessTokenInactiveTimer = function(a) {
                this.accessTokenInactiveTimer = this.setTimer(this.settings.eraseAccessToken, a, this.accessTokenInactiveTimer)
            }

It appears seems that fn() doesn't exist at the time it runs.

It correlates to this line of code:

Helpers.prototype.setTimer = function(fn, delay, oldTimer) {
if (oldTimer) {
clearTimeout(oldTimer);
}
setTimeout(function() {
fn();
}, delay);
};

Any ideas? I literally have thousands of these bug reports for this little line. It doesn't affect anything per say, but it may be the reason that chrome sessions don't always expire gracefully.

@justincy
Copy link
Contributor

I think the problem is caused by these lines:

Helpers.prototype.setAccessTokenInactiveTimer = function(delay) {
this.accessTokenInactiveTimer = this.setTimer(this.settings.eraseAccessToken, delay, this.accessTokenInactiveTimer);
};
Helpers.prototype.setAccessTokenCreationTimer = function(delay) {
this.accessTokenCreationTimer = this.setTimer(this.settings.eraseAccessToken, delay, this.accessTokenCreationTimer);
};

this.settings.eraseAccessToken should be this.eraseAccessToken

@dovy
Copy link
Contributor Author

dovy commented Nov 20, 2015

Deployed. Testing.

@justincy
Copy link
Contributor

We're one step closer. There's a new error now

TypeError: Cannot set property 'accessToken' of undefined

It's caused by this line:

this.settings.accessToken = null;

I think the problem is due to the eraseAccessToken being passed around in a variable so that when it's called the this context is incorrect. See this jsFiddle for an example: http://jsfiddle.net/90164595/1/

If that's correct then the fix would be to replace this.eraseAccessToken in my previous comment with

this.eraseAccessToken.bind(this);

But bind is only supported by IE 9+. If that's a problem then you can try this:

// In a line above, save a reference to "this"
var self = this;

// Now replace this.eraseAccessToken with this line
function(){ self.eraseAccessToken() };

@justincy justincy added the Bug label Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants