sample.javascript.txt 7.1 KB

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