// test.js
// > node test.js
// define Edge
function Edge(x, y) {
this._x = x;
this._y = y;
};
Edge.prototype = {
get x(){ return this._x },
set x(val){ console.log('x is readonly') }, // 设置 x 为只读且无法更改
get y(){ return this._y },
set y(val){ console.log('y is readonly') }
};
Edge.prototype.showLocation = function() { return 'Location: (' + this._x + ', ' + this._y + ').' };
// use Edge
var eg = new Edge(23,23);
console.log(eg.x);
console.log(eg.y);
console.log(eg.showLocation()); // #=> Location: (23, 23).
eg.x = 30; // 测试能否被修改,期望不能被改
eg.y = 30;
console.log(eg.showLocation()); // #=> Location: (23, 23). 这是我想要的效果
eg.showLocation = function() { return 'I am joking' }; // 测试能否被修改,期望不能被改
console.log(eg.showLocation()); // #=> I am joking 这不是我想要的效果
请问如何让 eg.showLocation = function() { return 'I am joking' }; 这句 失效 即 让 函数不被覆盖 .. ?