js变量、作用域

// 基本类型:4 'str' true/false undefined null       变量不能修改    不能添加属性
// 引用类型:[] {}                                                 变量可以修改

 

instanceof检测类型只能引用类型,不能基本类型consloe.log([] instanceof Array) consloe.log({} instanceof Object)     

// instanceof
// console.log([] instanceof Array);
// console.log([] instanceof Object);
// console.log({} instanceof Object);
// console.log({} instanceof Array);

 

// 作用域链
// var name = 'xm';
// function fn() {
// var name = 'xh';
// var sex = 'male';
// function fn2() {
// var name = 'xhei';
// var age = 18;
// }
// }

 

// 延长作用域链
// var person = {};
// person.name = 'xm';
// person.sex = 'male';
// var score = 4;

// with(person) {      //不推荐使用with
// name = 'xh';
// sex = 'female';
// score = 44;
// }
// console.log(person.name);
// console.log(person.sex);
// console.log(score);

 

 

垃圾收集机制

//垃圾收集机制:释放无用的数据,回收内存
//自动
//JS
//手动
//Objective-C
//原理:找出没用数据,打上标记,释放其内存;周期性执行
//标识无用数据的策略
//标记清除
//环境中的变量
//引用计数
var xm = {
name: 'xm',
age: 18
}; // 1
var xh = xm; // 2
xh = {}; // 1
xm = {}; // 0

//网景Netscape
//循环引用
function fn(argument) {
var xm = {}; // 1
var xh = {}; // 1
}
fn();
xm = null; // 0
xh = null; // 0

function fn(argument) {
var xm = {}; // 1
var xh = {}; // 1
xm.wife = xh; // 2
xh.husband = xm; // 2
}
fn();
xm = null; // 1
xh = null; // 1

//IE
//JS:DOM和BOM
//C++ COM

var obj = {};
var elem = document.getElementById('box'); // DOM
elem.someAttr = obj;
obj.someProperty = elem;

elem.someAttr = null;
obj.someProperty = null;

//内存管理
//Web浏览器 < 桌面应用程序
//null
var arr = [...];
//...
//... // arr
arr = null;
//...
//...
//...

 

 

// arguments.callee
// function add(num1, num2) {
// alert(arguments.callee);
// return num1 + num2;
// }
// add();

转载于:https://www.cnblogs.com/jian1234/p/10135349.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值