How to prove that function in js is a reference type?

146 0
var obj = {};
var obj2 = obj;
obj.name = 'jason';
console.log(obj);//Object {name:"jason"}
console.log(obj2);//Object {name:"jason"}

The above code can prove that the object is a reference type

How to prove function.

update

I used name.

 var a = function(){};
 var b = a;
 a.name = 'jason';
 console.log(a.name);//啥也没有
 console.log(b.name);//啥也没有

This is why.

2 Answers

61 1

This isn't the same reason, because function is also an object.

96 3

If I say all null types are reference types ( except and undefined ), do you want to trust.

...