使用严格导致未定义的函数



我正在尝试组织我的js文件并遵循建议的模块模式。当我在此模式中使用"use-strict"时,函数被声明为未定义,如果没有"use-strict"方法,该函数就可以正常工作。是否建议使用严格模式,如果是,为什么该功能无法使用它?

var envy = (function( $ ) {
'use strict';
/**
* Viewport adjusments.
*
* @since 1.0.0
*/
irp_viewportadjst = function() {
$('meta[name="viewport"]').attr('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
},
/**
* Fire events on document ready, and bind other events.
*
* @since 1.0.0
*/
ready = function() {
irp_viewportadjst();
};
// Only expose the ready function to the world
return {
ready: ready
};
})( jQuery );
jQuery( envy.ready );

代码中需要变量声明提升。严格模式声明要求更早地定义函数名称。 定义函数名称var irp_viewportadjst, ready;或 更改代码如下

var envy = (function( $ ) {
'use strict';
/**
* Viewport adjusments.
*
* @since 1.0.0
*/
var irp_viewportadjst = function() {
$('meta[name="viewport"]').attr('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0');
};
/**
* Fire events on document ready, and bind other events.
*
* @since 1.0.0
*/
var ready = function() {
irp_viewportadjst();
};
// Only expose the ready function to the world
return {
ready: ready
};
})( jQuery );
jQuery( envy.ready );

最新更新