Skip to content

Instantly share code, notes, and snippets.

@bga
Created November 15, 2010 20:02
Show Gist options
  • Save bga/700858 to your computer and use it in GitHub Desktop.
Save bga/700858 to your computer and use it in GitHub Desktop.

Problem

var cache = {};

var _gen = function(name)
{
  if(cache.hasOwnProperty(name))
    return cache[name]; 
  
  // ...
  
  return cache[name] = result;
};

_gen('__proto__') // oops!
_gen('__count__') // removed in gecko2. good
_gen('__parent__') // removed in gecko2. good

Also 1,{proto: 1}.proto === 1 // false 1,{proto: ''}.proto === '' // false 1,{proto: true}.proto === true // false

Solution

Remove all own __xxx__ properties from object and create some vendor specific API as __defineGetter__ ie for __proto__ -> Object#v8SetPrototype or Object#__setPrototype__

Good behavior in SM. var a = {proto: null}; 1,{}.hasOwnProperty.call(a, 'proto') // false; 1,{}.hasOwnProperty.call(a, 'count') // false; 1,{}.hasOwnProperty.call(a, 'parent') // false; a.proto // undefined a.parent // undefined a.count // undefined But in V8 var a = {proto: null}; 1,{}.hasOwnProperty.call(a, 'proto') // true; a.proto // null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment