WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 19 months ago

#38809 new defect (bug)

Better wp namespace in password-strength-meter.js

Reported by: afercia Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Administration Keywords: needs-patch
Focuses: javascript Cc:

Description

Currently, password-strength-meter.js uses this pattern to pass the wp object as argument:

window.wp = window.wp || {};

var passwordStrength;
(function($){
	wp.passwordStrength = {
...

})(jQuery);

so wp inside the IIFE is, technically, undefined, even if WordPress considers wp a global object. Also the first line is pointless if then window.wp is not passed as argument.

Change History (2)

#1 @andg
19 months ago

Invoking a typeof on the wp variable in the IIFE actually returns "object", not "undefined", since any variable not otherwise found is attributed to the global window object by default by the browser.

But yeah, passing it as a second argument would remove all uncertainties, and would probably be a better approach overall.

Note: See TracTickets for help on using tickets.