1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | (function (name, context, definition) {
|
9 | if (typeof module != 'undefined' && module.exports)
|
10 | module.exports = definition()
|
11 | else
|
12 | context[name] = definition()
|
13 | })('prr', this, function() {
|
14 |
|
15 | var setProperty = typeof Object.defineProperty == 'function'
|
16 | ? function (obj, key, options) {
|
17 | Object.defineProperty(obj, key, options)
|
18 | return obj
|
19 | }
|
20 | : function (obj, key, options) {
|
21 | obj[key] = options.value
|
22 | return obj
|
23 | }
|
24 |
|
25 | , makeOptions = function (value, options) {
|
26 | var oo = typeof options == 'object'
|
27 | , os = !oo && typeof options == 'string'
|
28 | , op = function (p) {
|
29 | return oo
|
30 | ? !!options[p]
|
31 | : os
|
32 | ? options.indexOf(p[0]) > -1
|
33 | : false
|
34 | }
|
35 |
|
36 | return {
|
37 | enumerable : op('enumerable')
|
38 | , configurable : op('configurable')
|
39 | , writable : op('writable')
|
40 | , value : value
|
41 | }
|
42 | }
|
43 |
|
44 | , prr = function (obj, key, value, options) {
|
45 | var k
|
46 |
|
47 | options = makeOptions(value, options)
|
48 |
|
49 | if (typeof key == 'object') {
|
50 | for (k in key) {
|
51 | if (Object.hasOwnProperty.call(key, k)) {
|
52 | options.value = key[k]
|
53 | setProperty(obj, k, options)
|
54 | }
|
55 | }
|
56 | return obj
|
57 | }
|
58 |
|
59 | return setProperty(obj, key, options)
|
60 | }
|
61 |
|
62 | return prr
|
63 | }) |
\ | No newline at end of file |