XIANFESchool / FE-problem-collection

前端问题收集和知识经验总结
https://github.com/ShuyunXIANFESchool/FE-problem-collection/issues
63 stars 22 forks source link

document 和 $document 的区别? #9

Open hjzheng opened 8 years ago

hjzheng commented 8 years ago

区别

$document 等于 angular.element(window.document) 实际上它是 jqLite 对 window.document的包装 $window.document 等于 window.document 它们都是 DOM element document.

$window.document === $document[0] //true

联想

window 和 $window 的区别?

$window 其实是 AngularJS 将全局 window 对象包装成的服务

settimeout 和 $timeout 的区别?

Angular's wrapper for window.setTimeout. The fn function is wrapped into a try/catch block and delegates any exceptions to $exceptionHandler service.

$timeout([fn], [delay], [invokeApply], [Pass]);

注意 $timeout 第三个参数,是否调用 apply 方法, 这是 AngularJS 性能的一个优化点。

setInterval 和 $setInterval 的区别?

区别同上, 可以参考官方API https://docs.angularjs.org/api/ng/service/$interval

mayufo commented 8 years ago

真及时!