在此代码中,原型仍然可以更改.
我怎样才能阻止原型的改变?
var a = {a:1}
var b={b:1}
var c = Object.create(a)
Object.getPrototypeOf(c) //a
c.__proto__ = b;
Object.getPrototypeOf(c) //b
var d = Object.create(null)
Object.getPrototypeOf(d) //null
d.__proto__ = b;
Object.getPrototypeOf(d) //null
Run Code Online (Sandbox Code Playgroud) var arr = [5, 2, 1, -10, 8];
arr.sort(function(a, b) {
console.log(a,b)
return b - a;
}) ; // 8, 5, 2, 1, -10
Run Code Online (Sandbox Code Playgroud)
这个回调如何工作?
选择a和b的原则是什么?
请从内部解释这个特例.
输出console.log(首先,请解释此输出):
5 2
2 1
1 -10
-10 8
1 8
2 8
5 8
Run Code Online (Sandbox Code Playgroud)