![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js
Microstrong0305
菜鸟程序猿
展开
-
模拟实现ES5中原生的bind函数
模拟原生bind看到这个题目,首先要明确bind的用法,知道自己要完成一个什么样的目标。1. 对于bind,大家都知道其可以改变this的指向。既然说到this,就回顾一下this的几种使用场景: I. 作为构造函数执行(在执行构造函数时,this <- {}, this.__proto__ <- 构造函数.prototype,执行构造函数中的代码(如this.属性名 <- 属性值),原创 2017-08-10 18:30:45 · 1641 阅读 · 1 评论 -
函数声明 VS. 函数表达式
昨晚室友扔我一道前端JS面试题,我仔细看了一下,给出了答案,果不其然,有两个地方答错了,这里就记录一下。题目function Foo(){ getName = function(){alert(1)}; return this; } Foo.getName = function(){alert(2)}; Foo.prototype.getName = function(){alert原创 2017-08-12 14:14:24 · 675 阅读 · 0 评论