diff.lhs.txt 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. © Microsoft. All rights reserved.
  3. This library is supported for use in Windows Tailored Apps only.
  4. Build: 6.2.8100.0
  5. Version: 0.5
  6. */
  7. (function (global, undefined) {
  8. "use strict";
  9. undefinedVariable = {};
  10. undefinedVariable.prop = 5;
  11. function initializeProperties(target, members) {
  12. var keys = Object.keys(members);
  13. var properties;
  14. var i, len;
  15. for (i = 0, len = keys.length; i < len; i++) {
  16. var key = keys[i];
  17. var enumerable = key.charCodeAt(0) !== /*_*/95;
  18. var member = members[key];
  19. if (member && typeof member === 'object') {
  20. if (member.value !== undefined || typeof member.get === 'function' || typeof member.set === 'function') {
  21. if (member.enumerable === undefined) {
  22. member.enumerable = enumerable;
  23. }
  24. properties = properties || {};
  25. properties[key] = member;
  26. continue;
  27. }
  28. }
  29. // These next lines will be deleted
  30. if (!enumerable) {
  31. properties = properties || {};
  32. properties[key] = { value: member, enumerable: enumerable, configurable: true, writable: true }
  33. continue;
  34. }
  35. target[key] = member;
  36. }
  37. if (properties) {
  38. Object.defineProperties(target, properties);
  39. }
  40. }
  41. (function (rootNamespace) {
  42. // Create the rootNamespace in the global namespace
  43. if (!global[rootNamespace]) {
  44. global[rootNamespace] = Object.create(Object.prototype);
  45. }
  46. // Cache the rootNamespace we just created in a local variable
  47. var _rootNamespace = global[rootNamespace];
  48. if (!_rootNamespace.Namespace) {
  49. _rootNamespace.Namespace = Object.create(Object.prototype);
  50. }
  51. function defineWithParent(parentNamespace, name, members) {
  52. /// <summary locid="1">
  53. /// Defines a new namespace with the specified name, under the specified parent namespace.
  54. /// </summary>
  55. /// <param name="parentNamespace" type="Object" locid="2">
  56. /// The parent namespace which will contain the new namespace.
  57. /// </param>
  58. /// <param name="name" type="String" locid="3">
  59. /// Name of the new namespace.
  60. /// </param>
  61. /// <param name="members" type="Object" locid="4">
  62. /// Members in the new namespace.
  63. /// </param>
  64. /// <returns locid="5">
  65. /// The newly defined namespace.
  66. /// </returns>
  67. var currentNamespace = parentNamespace,
  68. namespaceFragments = name.split(".");
  69. for (var i = 0, len = namespaceFragments.length; i < len; i++) {
  70. var namespaceName = namespaceFragments[i];
  71. if (!currentNamespace[namespaceName]) {
  72. Object.defineProperty(currentNamespace, namespaceName,
  73. { value: {}, writable: false, enumerable: true, configurable: true }
  74. );
  75. }
  76. currentNamespace = currentNamespace[namespaceName];
  77. }
  78. if (members) {
  79. initializeProperties(currentNamespace, members);
  80. }
  81. return currentNamespace;
  82. }
  83. function define(name, members) {
  84. /// <summary locid="6">
  85. /// Defines a new namespace with the specified name.
  86. /// </summary>
  87. /// <param name="name" type="String" locid="7">
  88. /// Name of the namespace. This could be a dot-separated nested name.
  89. /// </param>
  90. /// <param name="members" type="Object" locid="4">
  91. /// Members in the new namespace.
  92. /// </param>
  93. /// <returns locid="5">
  94. /// The newly defined namespace.
  95. /// </returns>
  96. return defineWithParent(global, name, members);
  97. }
  98. // Establish members of the "WinJS.Namespace" namespace
  99. Object.defineProperties(_rootNamespace.Namespace, {
  100. defineWithParent: { value: defineWithParent, writable: true, enumerable: true },
  101. define: { value: define, writable: true, enumerable: true }
  102. });
  103. })("WinJS");
  104. (function (WinJS) {
  105. function define(constructor, instanceMembers, staticMembers) {
  106. /// <summary locid="8">
  107. /// Defines a class using the given constructor and with the specified instance members.
  108. /// </summary>
  109. /// <param name="constructor" type="Function" locid="9">
  110. /// A constructor function that will be used to instantiate this class.
  111. /// </param>
  112. /// <param name="instanceMembers" type="Object" locid="10">
  113. /// The set of instance fields, properties and methods to be made available on the class.
  114. /// </param>
  115. /// <param name="staticMembers" type="Object" locid="11">
  116. /// The set of static fields, properties and methods to be made available on the class.
  117. /// </param>
  118. /// <returns type="Function" locid="12">
  119. /// The newly defined class.
  120. /// </returns>
  121. constructor = constructor || function () { };
  122. if (instanceMembers) {
  123. initializeProperties(constructor.prototype, instanceMembers);
  124. }
  125. if (staticMembers) {
  126. initializeProperties(constructor, staticMembers);
  127. }
  128. return constructor;
  129. }
  130. function derive(baseClass, constructor, instanceMembers, staticMembers) {
  131. /// <summary locid="13">
  132. /// Uses prototypal inheritance to create a sub-class based on the supplied baseClass parameter.
  133. /// </summary>
  134. /// <param name="baseClass" type="Function" locid="14">
  135. /// The class to inherit from.
  136. /// </param>
  137. /// <param name="constructor" type="Function" locid="9">
  138. /// A constructor function that will be used to instantiate this class.
  139. /// </param>
  140. /// <param name="instanceMembers" type="Object" locid="10">
  141. /// The set of instance fields, properties and methods to be made available on the class.
  142. /// </param>
  143. /// <param name="staticMembers" type="Object" locid="11">
  144. /// The set of static fields, properties and methods to be made available on the class.
  145. /// </param>
  146. /// <returns type="Function" locid="12">
  147. /// The newly defined class.
  148. /// </returns>
  149. if (baseClass) {
  150. constructor = constructor || function () { };
  151. var basePrototype = baseClass.prototype;
  152. constructor.prototype = Object.create(basePrototype);
  153. Object.defineProperty(constructor.prototype, "_super", { value: basePrototype });
  154. Object.defineProperty(constructor.prototype, "constructor", { value: constructor });
  155. if (instanceMembers) {
  156. initializeProperties(constructor.prototype, instanceMembers);
  157. }
  158. if (staticMembers) {
  159. initializeProperties(constructor, staticMembers);
  160. }
  161. return constructor;
  162. } else {
  163. return define(constructor, instanceMembers, staticMembers);
  164. }
  165. }
  166. function mix(constructor) {
  167. /// <summary locid="15">
  168. /// Defines a class using the given constructor and the union of the set of instance members
  169. /// specified by all the mixin objects. The mixin parameter list can be of variable length.
  170. /// </summary>
  171. /// <param name="constructor" locid="9">
  172. /// A constructor function that will be used to instantiate this class.
  173. /// </param>
  174. /// <returns locid="12">
  175. /// The newly defined class.
  176. /// </returns>
  177. constructor = constructor || function () { };
  178. var i, len;
  179. for (i = 0, len = arguments.length; i < len; i++) {
  180. initializeProperties(constructor.prototype, arguments[i]);
  181. }
  182. return constructor;
  183. }
  184. // Establish members of "WinJS.Class" namespace
  185. WinJS.Namespace.define("WinJS.Class", {
  186. define: define,
  187. derive: derive,
  188. mix: mix
  189. });
  190. })(WinJS);
  191. })(this);