Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. module.exports = extend;
  2. /*
  3. var obj = {a: 3, b: 5};
  4. extend(obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  5. obj; // {a: 4, b: 5, c: 8}
  6. var obj = {a: 3, b: 5};
  7. extend({}, obj, {a: 4, c: 8}); // {a: 4, b: 5, c: 8}
  8. obj; // {a: 3, b: 5}
  9. var arr = [1, 2, 3];
  10. var obj = {a: 3, b: 5};
  11. extend(obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
  12. arr.push(4);
  13. obj; // {a: 3, b: 5, c: [1, 2, 3, 4]}
  14. var arr = [1, 2, 3];
  15. var obj = {a: 3, b: 5};
  16. extend(true, obj, {c: arr}); // {a: 3, b: 5, c: [1, 2, 3]}
  17. arr.push(4);
  18. obj; // {a: 3, b: 5, c: [1, 2, 3]}
  19. extend({a: 4, b: 5}); // {a: 4, b: 5}
  20. extend({a: 4, b: 5}, 3); {a: 4, b: 5}
  21. extend({a: 4, b: 5}, true); {a: 4, b: 5}
  22. extend('hello', {a: 4, b: 5}); // throws
  23. extend(3, {a: 4, b: 5}); // throws
  24. */
  25. function extend(/* [deep], obj1, obj2, [objn] */) {
  26. var args = [].slice.call(arguments);
  27. var deep = false;
  28. if (typeof args[0] == 'boolean') {
  29. deep = args.shift();
  30. }
  31. var result = args[0];
  32. if (isUnextendable(result)) {
  33. throw new Error('extendee must be an object');
  34. }
  35. var extenders = args.slice(1);
  36. var len = extenders.length;
  37. for (var i = 0; i < len; i++) {
  38. var extender = extenders[i];
  39. for (var key in extender) {
  40. if (Object.prototype.hasOwnProperty.call(extender, key)) {
  41. var value = extender[key];
  42. if (deep && isCloneable(value)) {
  43. var base = Array.isArray(value) ? [] : {};
  44. result[key] = extend(
  45. true,
  46. Object.prototype.hasOwnProperty.call(result, key) && !isUnextendable(result[key])
  47. ? result[key]
  48. : base,
  49. value
  50. );
  51. } else {
  52. result[key] = value;
  53. }
  54. }
  55. }
  56. }
  57. return result;
  58. }
  59. function isCloneable(obj) {
  60. return Array.isArray(obj) || {}.toString.call(obj) == '[object Object]';
  61. }
  62. function isUnextendable(val) {
  63. return !val || (typeof val != 'object' && typeof val != 'function');
  64. }