分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

JS模块机制

发布时间:2023-09-06 02:27责任编辑:胡小海关键词:暂无标签

 代码模块

Require

.1. 加载指定代码 并执行

  1. 第二次加载不执行  ,但会执行module.exports

require返回值  module.exports= “dddd”,函数,

 Var 模块名=require(“模块文件”)

模块名.函数

 

This 机制

函数.call 显式的传递this

function my_func(){

  console.log(this);

}

my_func.call({});

 

var tools={

   myfunc:my_func

}

tools.myfunc();  //表.函数key()  -->  this - ->  表隐式

 

//强制绑定this

var newf=my_func.bind({name:"gaga到底"});

newf();

//This 回调机制

/*

在函数里面访问this,this由调用的环境来决定 不确定 不使用

显式的传递this,函数.call(this对象,参数)

隐式的传递this,表.key函数(参数),   this-- > 表

强制bind this 优先级最高.

*/

参考文章

别再为了this发愁了------JS中的this机制

https://www.cnblogs.com/front-Thinking/p/4364337.html

 

 

New与构造函数

每一个函数都有一个表 prototype

 

New  类似 其他语言创建一个类

1创建一个新表

2 创建一个新表 this 传递 调用person函数

3 person构造函数里面prototype这个表赋值到新的表的.__proto___

4 返回这个新表

模拟了 类和 实例

 

console.log(Math.PI);//prototype); function person (name,age){ ??this.name=name;this.age=age;}person.prototype.get_age=function(){ ?return this.age;}console.log(person.prototype);var b=new person("b",220) console.log(person.prototype);console.log(b);console.log(b.__proto__);console.log(b.get_age());

 

 

 

 

 

JS模块机制

原文地址:https://www.cnblogs.com/iflii/p/10189797.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved