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

How is sticky-position finding out native support? #2

Closed
juhaelee opened this issue Mar 7, 2016 · 1 comment
Closed

How is sticky-position finding out native support? #2

juhaelee opened this issue Mar 7, 2016 · 1 comment

Comments

@juhaelee
Copy link

juhaelee commented Mar 7, 2016

const nativeSupport = (function(){      
        if (this.isSupported !== null) {
            return this.isSupported;
        } else {
            const style = document.createElement('test').style;
            style.cssText = ['-webkit-', '-ms-', ''].map(prefix => `position: ${prefix}sticky`).join(';');
            this.isSupported = style.position.indexOf('sticky') !== -1;
            return this.isSupported;
        }
    }).bind({isSupported: null});

Wouldn't isSupported always be null, so wouldn't the else clause always be executed?

@jackmoore

@jackmoore
Copy link
Owner

The first time the function is called, the else clause will execute and set this.isSupported to be either true or false. Know that bind is being invoked just once in the creation of the function, and each call to the function references the same object that was passed to bind, so value of this.isSupported is persistent between calls.

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