前端技能汇总

JavaScript

前端技能汇总 Frontend Knowledge Structure

深入浅出Node.js 书籍pdf
《深入浅出Node.js》的相关代码

Javascript&jQuery教程 pdf

html & css教程 pdf

高性能JavaScript_中英双语版 pdf

跳坑之js调用另一个js文件中函数

方法1;

在html文件中加入两个脚本程序,注意,加入的位置在和两个标签之间,(也有的在两个标签之间加入的),代码如下:

js 复制代码
</head>
  <script src="hello.js"></script>
  <script src="renderer.js"></script>
  <body>

之后在hello.js中直接调用函数就行。

test('click', 'asynchronous message', 'ping');

方法2

renderer.js中使用exports导出函数:

js 复制代码
//在这里面写好函数的封装,然后在hello.js中调用
var test = function(struct, buttonId, msg){
    const asyncMsgBtn = document.getElementById(buttonId);
    asyncMsgBtn.addEventListener(struct, function(){
        switch(struct){
            case 'click':
                ipc.send('asynchronous-message', msg);
                console.log("调用成功");
                break;
            default:
                console.log('Error!!!')
        }
    })
}
//这种方式是成功的
exports.test = test;
//这种方式也是可以得
//module.exports.test = test;

而hello.js中对于代码的使用如下:

js 复制代码
//利用require加载模块
const renderer = require('./renderer')

renderer.test('click', 'asynchronous message', 'ping');
renderer.test('click', 'changeView', 'change');

可以说,这种方式完全符合我们程序封装的概念,思路统一,结构规整,个人最爱。
<>

相关推荐
KaMeidebaby1 小时前
卡梅德生物技术快报|PD1 单克隆抗体定制配套 N 糖全谱质控开发
前端·人工智能·算法·数据挖掘·数据分析
nuIl2 小时前
实现一个 Coding Agent(3):工具调用
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(4):ReAct 循环
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(1):一次 LLM 调用
前端·agent·cursor
nuIl3 小时前
实现一个 Coding Agent(2):让 LLM 流式响应
前端·agent·cursor
copyer_xyf3 小时前
Python 异常处理
前端·后端·python
sugar__salt3 小时前
从栈队列数据结构到JS原型面向对象全解
前端·javascript·数据结构
独特的螺狮粉3 小时前
篮球集训班器具管理系统 - 鸿蒙PC Electron框架完整技术实现指南
前端·javascript·华为·electron·前端框架·开源·鸿蒙
pusheng20253 小时前
IFSJ全英文专访:中国创新力量重塑先进气体感知技术,赋能全球关键基础设施安全
前端·网络·人工智能·物联网·安全
AI_零食4 小时前
番茄钟鸿蒙PC Electron框架完成:状态机、定时器管理与专注力工具设计
前端·javascript·华为·electron·开源·鸿蒙·鸿蒙系统