Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
javascript全局变量控制
npm install --save hey-global
直接使用script标签引用js文件,可以通过github下载,引用build/global.js文件
使用的时候,直接引用G变量
G.set('GENDER', {
1: '先生',
2: '女士',
})
一般使用hey-global的时候,我们建议定义成全局变量G,如果你使用的是webpack,可以做如下配置:
new webpack.ProvidePlugin({
G: 'hey-global'
});
import G from 'hey-global';
// 如果是js直接引用的话,直接引用G变量
// 或者直接配置webpack全局变量,则无需引用
G.set('GENDER', {
1: '先生',
2: '女士',
})
// 存储用户信息
G.set('Account', {});
// 存储用户权限
G.set('Admin', true);
// 存储环境变量
G.set('env', {
fileOs: 'http://www.download.com',
socketOs: 'ws://www.socket.com',
});
const gender = G.get('GENDER')
// {
// 1: '先生',
// 2: '女士',
// }
// 获取用户信息
const account = G.get('Account');
// {}
// 获取用户权限
const isAdmin = G.get('Admin');
// true
// 获取环境变量
const env = G.get('env');
// {
// fileOs: 'http://www.download.com',
// socketOs: 'ws://www.socket.com',
// }
let todoTrigger = G.addlistener('NEW_TODO', (data)=>{
console.log(`new todo: ${date.message}`)
});
G.trigger('NEW_TODO', {message: 'go home'});
// new todo: go home
当无需处理的时候,可以通过removelistener删除监听
G.removelistener(todoTrigger);
FAQs
global.js, global, js
The npm package hey-global receives a total of 15 weekly downloads. As such, hey-global popularity was classified as not popular.
We found that hey-global demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.