private
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"homepage": "http://github.com/benjamn/private", | ||
@@ -26,2 +26,3 @@ "repository": { | ||
}, | ||
"license": "MIT", | ||
"main": "private.js", | ||
@@ -28,0 +29,0 @@ "scripts": { |
"use strict"; | ||
var defProp = Object.defineProperty || function(obj, name, desc) { | ||
// Normal property assignment is the best we can do if | ||
// Object.defineProperty is not available. | ||
obj[name] = desc.value; | ||
}; | ||
var originalObject = Object; | ||
var originalDefProp = Object.defineProperty; | ||
var originalCreate = Object.create; | ||
function defProp(obj, name, value) { | ||
if (originalDefProp) try { | ||
originalDefProp.call(originalObject, obj, name, { | ||
value: value, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
} catch (definePropertyIsBrokenInIE8) { | ||
obj[name] = value; | ||
} else { | ||
obj[name] = value; | ||
} | ||
} | ||
// For functions that will be invoked using .call or .apply, we need to | ||
@@ -15,7 +28,12 @@ // define those methods on the function objects themselves, rather than | ||
function makeSafeToCall(fun) { | ||
defProp(fun, "call", { value: fun.call }); | ||
defProp(fun, "apply", { value: fun.apply }); | ||
if (fun) { | ||
defProp(fun, "call", fun.call); | ||
defProp(fun, "apply", fun.apply); | ||
} | ||
return fun; | ||
} | ||
makeSafeToCall(originalDefProp); | ||
makeSafeToCall(originalCreate); | ||
var hasOwn = makeSafeToCall(Object.prototype.hasOwnProperty); | ||
@@ -26,16 +44,10 @@ var numToStr = makeSafeToCall(Number.prototype.toString); | ||
var cloner = function(){}; | ||
var create = Object.create || function(prototype, properties) { | ||
function create(prototype) { | ||
if (originalCreate) { | ||
return originalCreate.call(originalObject, prototype); | ||
} | ||
cloner.prototype = prototype || null; | ||
var obj = new cloner; | ||
return new cloner; | ||
} | ||
// The properties parameter is unused by this module, but I want this | ||
// shim to be as complete as possible. | ||
if (properties) | ||
for (var name in properties) | ||
if (hasOwn.call(properties, name)) | ||
defProp(obj, name, properties[name]); | ||
return obj; | ||
}; | ||
var rand = Math.random; | ||
@@ -54,9 +66,7 @@ var uniqueKeys = create(null); | ||
// for the typical use of this module. | ||
defProp(exports, "makeUniqueKey", { | ||
value: makeUniqueKey | ||
}); | ||
defProp(exports, "makeUniqueKey", makeUniqueKey); | ||
function wrap(obj, value) { | ||
var old = obj[value.name]; | ||
defProp(obj, value.name, { value: value }); | ||
defProp(obj, value.name, value); | ||
return old; | ||
@@ -109,3 +119,3 @@ } | ||
defProp(object, brand, { value: vault }); | ||
defProp(object, brand, vault); | ||
} | ||
@@ -127,4 +137,2 @@ | ||
defProp(exports, "makeAccessor", { | ||
value: makeAccessor | ||
}); | ||
defProp(exports, "makeAccessor", makeAccessor); |
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
15138
6
0
171