主要是第一题
- /*
- var length = 10;
- function fn(){
- console.log(this.length);
- }
- var obj = {
- length: 5,
- method: function(a) {
- a(); // ? 由于定义length用的var,所以不是全局变量这里显示undefined
- arguments[0](); // ? 同一个函数对象,这里通过arguments对象引用来访问,所以最后显示的是arguments的length
- }
- }
- obj.method(fn);
- //就相当于一个类创建两个对象,不同的对象调用同一个方法,里面this结果是调用对象
- */
- /*
- ~function() {
- console.log(typeof next) // ?
- ~function next() {
- console.log(typeof next) // ?
- }()
- }();
- //看成如下
- (function(){
- console.log(typeof next);
- (function next(){
- console.log(typeof next);
- })();
- })()
- */
- /*
- a=3;
- a.prop=4;
- console.log(a+a.prop); //NaN
- //console.log(a);
- //console.log(a.prop);
- */
- /*
- a='a';
- a.prop='b';
- console.log(a+a.prop); //aundefined
- */
来源: https://www.oschina.net/code/snippet_1419328_58648