This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 添加监听 # | |
| 通过on 来绑定事件 | |
| on 绑定的问题:只能给元素绑定一次相同事件。第二次会覆盖掉第一次。 | |
| 通过on 绑定的取消 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 阻止事件 # | |
| stopPropagation(); 阻止事件的传递 | |
| preventDefault(); 阻止元素的默认事件 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 闭包 # | |
| 其本质还是一个函数,能够访问其他函数内部变量的函数 | |
| # 条件: # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 匿名函数 # | |
| 匿名函数:其本质还是一个函数,但没有名字 | |
| 函数通过函数名来调用,才能执行。匿名函数无法通过名字调用。 | |
| 匿名函数的执行方法 | |
| 1.绑定给某一个事物 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 作用域 # | |
| 所谓的作用域 也被称为生命周期 | |
| 我们在使用数据时,会向计算机申请一块内存空间来保存数据。这块空间被称为变量,数组,对象等。 | |
| 计算机为了保证自身的运行速度,会在某个时间,将分配出去的内存收回。 | |
| 一个内存空间 从创建到被收回,这个过程被称为它的作用域或者生命周期。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 什么是对象? # | |
| 1.它是一个数据对象 | |
| 2.只要是对象,就可以有自己的私有属性(方法) | |
| 3.只要是new出来的,都是对象 | |
| 4.不同对象 肯定 不会相等 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 对象的创建 # | |
| 1.方式一:使用new来创建出函数对象 | |
| var obj = new Object(); | |
| obj.name = "cf"; | |
| console.log(obj); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 什么是原型? # | |
| 原型是一个对象,其他对象可以通过它实现属性继承。 | |
| 每个函数都有一个属性叫做prototype. | |
| 这个prototype的属性值是一个对象(属性的集合,再次强调!),默认的只有一个叫做constructor的属性,指向这个函数本身。 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 构造函数 # | |
| this: | |
| 1.在普通函数下,this指向的是window,因为所以全局的东西都是在window下的,例如函数myFun(),实际是window.myFun(); | |
| 2.有事件源的情况下,指向事件源本身 | |
| 3.在对象下,this指向的是对象自己本身(构造函数中,谁调用它,this就指向谁)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 工厂函数: # | |
| 把单个创建对象的过程封装到了一个函数中,每次需要创建对象时,调用该函数即可。 | |
| 特征 1.它本身是一个函数,也就是说函数具有的特征它都有 | |
| 2.它用来创建对象 | |
| 3.它像一个工厂一样,“生产”出来的对象都是“标准件”(拥有同样的属性)所以几乎每一个工厂函数都有参数,让同样的属性有不同的值。 | |
| 备注: 1.工厂函数基本都是需要参数的 |