@panzerdp/SnappyDevotedGoshawk
JavaScript

No description

repl talk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// ------------------- Shim ----------------------
const reduce = Function.bind.call(Function.call, Array.prototype.reduce);
const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable);
const concat = Function.bind.call(Function.call, Array.prototype.concat);
const keys = Reflect.ownKeys;

if (!Object.values) {
	Object.values = function values(O) {
		return reduce(keys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []);
	};
}

if (!Object.entries) {
	Object.entries = function entries(O) {
		return reduce(keys(O), (e, k) => concat(e, typeof k === 'string' && isEnumerable(O, k) ? [[k, O[k]]] : []), []);
	};
}
// ------------------ End of Shim ----------------------
let simpleColors = {  
  colorA: 'white',
  colorB: 'black'
};
let natureColors = {  
  colorC: 'green',
  colorD: 'yellow'
};
Object.setPrototypeOf(natureColors, simpleColors);  

console.log(Object.values(natureColors)); 
// => ['green', 'yellow']
console.log(Object.entries(natureColors));
// => [ ['colorC', 'green'], ['colorD', 'yellow'] ]
Native Browser JavaScript