Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cassandra/3.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
ES3的Javascript getter/setter_Javascript_Photoshop Script_Ecmascript 3 - Fatal编程技术网

ES3的Javascript getter/setter

ES3的Javascript getter/setter,javascript,photoshop-script,ecmascript-3,Javascript,Photoshop Script,Ecmascript 3,我尝试在Photoshop中实现以下函数(使用Javascript ES3编写脚本)。我怎样才能将其编写为与ES3兼容 function VParabola(s){ this.cEvent = null; this.parent = null; this._left = null; this._right = null; this.site = s; this.isLeaf = (this.site != null); } VParabola.p

我尝试在Photoshop中实现以下函数(使用Javascript ES3编写脚本)。我怎样才能将其编写为与ES3兼容

function VParabola(s){
    this.cEvent = null;
    this.parent = null;
    this._left = null;
    this._right = null;
    this.site = s;
    this.isLeaf = (this.site != null);
}

VParabola.prototype = {
    get left(){
        return this._left;
    },
    get right(){
        return this._right;
    },
    set left(p){
        this._left = p;
        p.parent = this;
    },
    set right(p){
        this._right = p;
        p.parent = this;
    }
};
您可以在构造函数中使用

function VParabola(s){
    this.cEvent = null;
    this.parent = null;
    var left = null;
    var right = null;
    this.site = s;
    this.isLeaf = (this.site != null);

    Object.defineProperty(this, 'right', {
        get: function () {
            return right;
        },
        set: function (value) {
            right = value;
        }
    })

    Object.defineProperty(this, 'left', {
        get: function () {
            return left;
        },
        set: function (value) {
            left = value;
        }
    })

 }

已定义的属性不应具有
\uu
前缀。回答得好。
Object.defineProperty
是ES5,所以我怀疑它是否有效?这不起作用-
Object.defineProperty
不是一个函数。您的环境是否支持
Object.defineProperty
?或者
Object.prototype.\uuu defineGetter\uuuu
?我相信Photoshop仅限于ES3-我得到
Object.defineProperty不是一个函数
是的,另一个呢?这是一个非标准的ES3扩展。尝试编写
对象。_udefinegetter__('right',function(){return right;})在VParabola函数中。仍然不是一个函数。我不知道我写的是否正确。应该是
VParabola.prototype.\uuu defineGetter\uuu('left',function(){返回这个。left;})(当然在构造函数之外)