博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
javascript相关
阅读量:7089 次
发布时间:2019-06-28

本文共 1752 字,大约阅读时间需要 5 分钟。

require.js

promise模式, jquery 的deffered对象。

use strict(使用严格模式) 符合很多的条件限制。

javascript的编译时和运行时, var function的概念有待追求清楚。

 

var keyword in javascript:

 If you're in a function then "var" will create a local variable, "no var" will look up the scope chain until it finds the variable or hits the global scope (at which point it will create it):

 

eval()函数的使用:

优点: 动态生成javascript代码。

(在某些场合,你不确定需要执行的具体代码,比如某个根据某元素的ID来对一个元素进行操作,但是这个ID确实生成的,不是预先知道的。)

缺点:

  1. Improper use of eval opens up your code for injection attacks

  2. Debugging can be more challenging (no line numbers, etc.)

  3. eval'd code executes more slowly (no opportunity to compile/cache eval'd code)

 

this关键字在javascript中的理解:

You can figure out what object this refers to by following a few simple rules:

  • By default, this refers to the global object.
  • When a function is called as a property on a parent object, this refers to the parent object inside that function.
  • When a function is called with the new operator, this refers to the newly created object inside that function.
  • When a function is called using call or apply, this refers to the first argument passed to call or apply. If the first argument is null or not an object, this refers to the global object.

sample for understanding:

http://stackoverflow.com/questions/8813871/understanding-this-in-javascript

http://net.tutsplus.com/tutorials/javascript-ajax/fully-understanding-the-this-keyword/

 

use strict的使用:

使用use strict的目的

1: 消除不合理的地方, 使代码更合理。

例子: 变量重名将报错而不是覆盖上一个,变量必须显示声明而不是默认为全局变量。

2: 更快,因为javascript允许动态绑定,所以可以在运行时才确定方法,变量。

      strict模式对一些情况不允许动态绑定,必须静态绑定,可以提高执行效率。

例子:禁止使用with语句,创建eval的变量作用域。

3:更加安全

例子:严格模式下无法删除变量。只有configurable设置为true的对象属性,才能被删除

         使用构造函数时,如果忘了加new,this不再指向全局对象,而是报错。

 

 

 

 

转载于:https://www.cnblogs.com/hushaowei/archive/2013/03/22/2975492.html

你可能感兴趣的文章
GraphQL和REST对比时需要注意些什么
查看>>
Ooui:在浏览器中运行.NET应用
查看>>
GitLab可完全管理Google Kubernetes Engine
查看>>
在 iOS 的 SQLite 数据库中应用 FMDB 库
查看>>
可执行镜像——开发环境的Docker化之路
查看>>
使用自选择创建团队
查看>>
基于组织目标采用合适的敏捷方法
查看>>
Spark性能调优之道——解决Spark数据倾斜(Data Skew)的N种姿势
查看>>
李彦宏宣布百度架构调整:智能云事业部升级
查看>>
NetBeans第一部分代码提交Apache
查看>>
支持医学研究的Apple开源移动框架
查看>>
使用人工智能测试软件
查看>>
InfoQ趋势报告:DevOps 和云计算
查看>>
Microsoft Edge中新的F12开发者工具
查看>>
为所有PHP-FPM容器构建单独的Nginx Docker镜像
查看>>
微软宣布Azure Functions正式支持Java
查看>>
抖音成2018年全球iOS设备上下载最多的应用\n
查看>>
IBM核心软件如何应对“互联网+”的技术挑战
查看>>
Weaveworks增加发布自动化和事件管理
查看>>
LeetCode[337] House Robber III
查看>>