Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(三)javascript高级程序设计: 变量,作用域与内存问题 #3

Open
3 tasks done
Quickeryi opened this issue Jun 6, 2017 · 0 comments
Open
3 tasks done

Comments

@Quickeryi
Copy link
Owner

Quickeryi commented Jun 6, 2017

本文旨在记录一些js变量、作用域与内存相关的一些核心概念

Every thing is javascript

  • 变量
  1. code:
// 不能给基本数据类型添加属性,**尽管不会报错**
var name = "name";
name.age = 1; // 不会报错
console.log(name.age); // undefined
  1. 概念: 引用类型数据存放在堆内存中,基本类型数据存放在栈内存
  • 延长作用域链:作用域链的前端添加一个变量对象,此时代码性能会下降
// with语句:with语句块内部被封装了一个局部作用域,其变量对象中包含着指定对象的所有属性和方法所作的变量申明
// try-catch语句:其变量对象中包含的是被抛出的错误对象的申明
// 当with和catch语句结束之后,作用域链会恢复到原先的状态
1.垃圾回收有两种方式:标记清除,引用计数
2.标记清除:目前主流的做法
3.引用计数:由于在循环引用中会出现永远无法释放对象问题,所以目前不在使用
@Quickeryi Quickeryi changed the title javascript高级程序设计: 变量,作用域与内存问题 (三)javascript高级程序设计: 变量,作用域与内存问题 Jun 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant