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

Should find return null when no nodes are found? #37

Open
Saartje87 opened this issue Aug 30, 2013 · 1 comment
Open

Should find return null when no nodes are found? #37

Saartje87 opened this issue Aug 30, 2013 · 1 comment

Comments

@Saartje87
Copy link
Owner

No description provided.

@jonkoops
Copy link
Contributor

Something I often do when creating i.e. a slider is finding a couple of nodes inside other nodes for validation purposes. Here's an over exaggerated example:

<div id="slider">
    <div class="slider-viewport">
        <div class="slides-wrapper">
            <div class="slide">Slide 1</div>
            <div class="slide">Slide 2</div>
            <div class="slide">Slide 3</div>
        </div>
    </div>
</div>
var Slider = PB.Class({

    construct: function ( target ) {

        this.node = PB.$(target);

        if( !this.node ) {
            return;
        }

        this.viewport = this.node.find('.slider-viewport');
        this.slidesWrapper = this.viewport.find('.slides-wrapper');
        this.slides = this.slidesWrapper.find('.slide');

        if( !this.viewport.length && 
            !this.slidesWrapper.length &&
            !this.slides.length ) {

            return;
        }

    }

});

If .find were to return null, I'd have to add an if statement for every call. This would obviously over-complicate production code.

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