$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>javascript - Need help about understand api, wp, $ syntax in WordPress plugin script|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin7PV0评论

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

Post a comment

comment list (0)

  1. No comments so far