Показать сообщение отдельно
  #20 (permalink)  
Старый 20.01.2015, 21:47
Аспирант
Посмотреть профиль Найти все сообщения от registrant
 
Регистрация: 15.01.2015
Сообщений: 39

kobezzza,
(function () {
    var toSource = Object.prototype.toSource;
 
    Object.defineProperty(Object.prototype, 'toSource', {
         writable: true,
         configurable: true,
         enumerable: false,
         value: function () {
            var clone = {};
             
            for (var key in this) {
                clone[key] = this[key];
            }
             
            return toSource.call(clone);
        }
    });
})();
 
var a = {a: 1};
var b = {
    __proto__: a,
    c: 1,
};
 
alert(eval(b.toSource())===b);

Но ты можешь проще выйти из этой ситуации
Object.prototype.toSource=function(){return this}
 
var a = {a: 1};
var b = {
    __proto__: a,
    c: 1,
};
 
alert(eval(b.toSource().a))
alert(eval(b.toSource())===b)

Все правильно работает, пока цирк не уехал.
Ответить с цитированием