Safari和Chrome上this.toSource()的等效之处是什么

时间:2019-10-09 11:00:39

标签: javascript google-chrome firefox safari

我有一些仅在Firefox上可用的代码,因为this.toSource()在Safari和Chrome上不起作用。如何制作可在Safari,Chrome和其他一些浏览器上使用的替代功能。香港专业教育学院试图用this.toString()取代它,这将无法在这里我的代码

var elements = [];
var rect = function() {
    this.x = 0;
    this.y = 0;
    this.width = 100;
    this.height = 100;
    this.background = "black";
    this.name = "rect"
};
rect.prototype.render = function() {
    if(this.toSource() != null) {
        elements[elements.length] = this.toSource();
    }
    // c = this.toString();
    // elements[elements.length] = c;
    var returnThing;
    for(var i in this) {
        returnThing += this[i]
    }
    returnThing = returnThing.replace(/NaNblackrect3D30/g, '');
    returnThing = returnThing.replace(/function()/g, '');
    returnThing = returnThing.replace(") {", '');
    elements[elements.length] = returnThing;
};

0 个答案:

没有答案