Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取重写的getter的值_Javascript - Fatal编程技术网

Javascript 获取重写的getter的值

Javascript 获取重写的getter的值,javascript,Javascript,我有这样的代码 function A(){} Object.defineProperties(A.prototype,{ 'propName' : { 'get' : function(){ return 'hallo'; }, 'set' : function( p ){ console.log( 'setting...' ); } } }); funct

我有这样的代码

function A(){}
Object.defineProperties(A.prototype,{
    'propName' : {
        'get' : function(){
            return 'hallo';
        },
        'set' : function( p ){
            console.log( 'setting...' );
        }
    }    
 });

function B(){
    A.call( this )
}
B.prototype = Object.create( new A(), {
    'propName' : {
        'get' : function(){
            //do something than call getter of parent prototype
        },
        'set' : function( p ){
            //do something than call setter of parent prototype
        },
    }
});
可以调用getter或setter的原型吗?如果可以,如何调用

Grettings…

是的,这是可能的

B.prototype = Object.create(A.prototype, {
  'propName': {
    get: function () {
      var desc = Object.getOwnPropertyDescriptor(A.prototype, 'propName');
      var value = desc.get.call(this);
      return 'altered ' + value;
    }
  }
});