admin管理员组

文章数量:1384511

I really new in Wordpress development and have a little bit of knowledge of jquery. I was trying to understand a WordPress plugin and also trying to understand the js code they wrote for the plugin. I don't understand what does the following code mean.

(function( api, wp, $ ) {
'use strict';

})( wp.customize, wp, jQuery );

what is api , wp and $ at the top and wp.customize , wp , jQuery at the bottom mean?

I really new in Wordpress development and have a little bit of knowledge of jquery. I was trying to understand a WordPress plugin and also trying to understand the js code they wrote for the plugin. I don't understand what does the following code mean.

(function( api, wp, $ ) {
'use strict';

})( wp.customize, wp, jQuery );

what is api , wp and $ at the top and wp.customize , wp , jQuery at the bottom mean?

Share Improve this question edited May 9, 2020 at 13:48 Prappo 1531 silver badge4 bronze badges asked May 4, 2020 at 10:16 xs-devxs-dev 153 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

It's an Immediately Invoked Function Expression (IIFE) - an anonymous function that executes itself after it has been defined. The variables at the bottom are taken from the global scope and are passed as parameters to the anonymous function.

So api represents wp.customize,
wp represents wp and
$ represents jQuery inside the function.

As I understand it, this function just tells you that strict mode (https://www.w3schools/js/js_strict.asp) is being used for the execution of jQuery Scripts of your WordPress customizer. api here just refers to the "connection" onto a specific part, which in this case is the wordpress customizer (https://developer.wordpress/themes/customize-api/).

本文标签: javascriptNeed help about understand apiWP syntax in WordPress plugin script