最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Need help about understand api, wp, $ syntax in WordPress plugin script

programmeradmin1浏览0评论

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/).

发布评论

评论列表(0)

  1. 暂无评论