javascript学习笔记之javascript core

obj 与 prototype
对象包含属性和方法,当在对象中没有找到相关的属性时,会根据__proto __去查找他的prototype对象,如果存在,则返回;否则,返回undefined。就好像:

var a = { x : 100 }
var b = { __proto__ : a  }
a.x; // 100

__proto __与prototype

__proto__ 会指向创建此对象的构造函数的prototype对象。这句话听起来可能很绕,大体的意思是js中所有东西都有自己的prototype,__proto__都会有所指,只是有时候没有找到那个你认为的那个。eg:function的__proto__指向Object.prototype

variable object

>A variable object is a container of data related with the execution context. It’s a special object associated with the context and which stores variables and function declarations are being defined within the context.

FE 如 (function baz(){})中baz不被包含在variable object中

scope chain
> if a variable is not found in the own scope (in the own variable/activation object), its lookup proceeds in the parent’s variable object, and so on.

从函数里面能够访问外面的作用域叫做scope chain,而从外面访问到里面的变量叫做闭包,而闭包也是解决作用域问题的方法。

常见的闭包的两种使用场景:

1.

function foo() {
  var x = 10;
  return function bar() {
    console.log(x);
  };
}
var returnedFunction = foo();
returnedFunction(); // 10, but not 20
2.

var x = 10;
function foo() {
  console.log(x);
}
(function (funArg) {
  var x = 20;
  funArg(); // 10, but not 20
})(foo); // pass "down" foo as a "funarg"

> A closure is a combination of a code block (in ECMAScript this is a function) and statically/lexically saved all parent scopes. Thus, via these saved scopes a function may easily refer free variables. by Dmitry Soshnikov

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值