javascript - 一道js面试题
PHP中文网
PHP中文网 2017-04-10 15:04:30
0
2
291

var write = document.write;
write("hello");
//能够正确执行吗?
//如果不正确,正确操作是怎样的?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
小葫芦

推荐你看这篇文章:Javascript中bind()方法的使用与实现

大家讲道理

不能正确执行,因为 write 函数丢掉了上下文。
正确的操作应该是:

1: var write = document.write.bind(document)

或者

2: write.call(document, "hello")
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template