Object.prototype.Clone = function () {
            var objClone;
            if (this.constructor == Object) {
                objClone = new this.constructor();
            } else {
                objClone = new this.constructor(this.valueOf());
            }
            for (var key in this) {
                if (objClone[key] != this[key]) {
                    if (typeof (this[key]) == 'object') {
                        objClone[key] = this[key].Clone();
                    } else {
                        objClone[key] = this[key];
                    }
                }
            }
            objClone.toString = this.toString;
            objClone.valueOf = this.valueOf;
            return objClone;
        }


valueof 与toString() 区别

 

                var obj = {

                    i: 10,

                    valueOf: function () { return this.i + 30; },

                    toString: function () { return this.valueOf() + 10; }

                }

                alert(obj > 20); // true

                alert(+obj); // 40

                alert(obj); // 50


相关文章:

  • 2021-09-25
  • 2022-02-13
  • 2022-12-23
  • 2020-09-25
  • 2022-01-01
  • 2021-11-05
  • 2022-12-23
  • 2022-02-26
猜你喜欢
  • 2022-03-08
  • 2021-11-25
  • 2022-12-23
相关资源
相似解决方案