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 the plugin template still use undefined passed as a parameter #124

Open
toniedzwiedz opened this issue Sep 7, 2016 · 1 comment

Comments

@toniedzwiedz
Copy link

This file provides an example of undefined being passed as an argument to a function:

;( function( $, window, document, undefined ) {
    //omitted for brevity
})($, window, document);

The idea here seems to be to make sure undefined is really undefined by not passing it into the actual call. However, I believe this is no longer necessary in ES5+ compliant browsers.

These days, it's actually safer not to do it as it introduces a way for a developer to introduce a local variable named undefined by accidentally calling the function with too many arguments. MDN seems to advise against that and personally, I agree.

Later in the same script, there's a comment saying:

    // undefined is used here as the undefined global variable in ECMAScript 3 is
    // mutable (ie. it can be changed by someone else). undefined isn't really being
    // passed in so we can ensure the value of it is truly undefined. In ES5, undefined
    // can no longer be modified.

I understand that the fact the template still uses this practice is a conscious decision based on the team's belief in continuing to do it to cater for pre-ES5 browsers. However, I think it should also be mentioned very explicitly that this actually introduces a risk in modern browsers and should only be done if one actually wants to support ES3 browsers.

What do you think?

@jstnbr
Copy link

jstnbr commented Apr 5, 2018

I agree with dropping it. The Javascript Wikipedia says "ECMAScript 5 was finally released in December 2009."

That means since December 2009 this technique has been obsolete.

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