jsduck 4.6.0 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -0
- data/Rakefile +4 -0
- data/js-classes/Array.js +494 -1
- data/js-classes/Date.js +22 -0
- data/js-classes/Function.js +80 -0
- data/js-classes/Object.js +638 -0
- data/js-classes/RegExp.js +1 -1
- data/js-classes/String.js +19 -1
- data/jsduck.gemspec +2 -2
- data/lib/jsduck/assets.rb +1 -1
- data/lib/jsduck/class.rb +2 -2
- data/lib/jsduck/members_index.rb +24 -12
- data/lib/jsduck/options.rb +5 -3
- data/lib/jsduck/welcome.rb +7 -4
- metadata +4 -4
data/js-classes/Date.js
CHANGED
@@ -996,4 +996,26 @@
|
|
996
996
|
* myVar = x.valueOf(); //assigns -424713600000 to myVar
|
997
997
|
*
|
998
998
|
* @return {Number} Date represented as milliseconds.
|
999
|
+
*/
|
1000
|
+
|
1001
|
+
// ECMAScript 5 methods
|
1002
|
+
|
1003
|
+
/**
|
1004
|
+
* @method toJSON
|
1005
|
+
* Returns a JSON representation of the Date object.
|
1006
|
+
*
|
1007
|
+
* Date instances refer to a specific point in time. Calling `toJSON()`
|
1008
|
+
* returns a JSON formatted string representing the Date object's
|
1009
|
+
* value. This method is generally intended to, by default, usefully
|
1010
|
+
* serialize Date objects during JSON serialization.
|
1011
|
+
*
|
1012
|
+
* var jsonDate = (new Date()).toJSON();
|
1013
|
+
* var backToDate = new Date(jsonDate);
|
1014
|
+
*
|
1015
|
+
* console.log("Serialized date object: " + jsonDate);
|
1016
|
+
* // Serialized date object: 2013-01-17T12:59:08.449Z
|
1017
|
+
*
|
1018
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
1019
|
+
*
|
1020
|
+
* @return {String} Date value in `YYYY-MM-DDTHH-MM-SS.MMMZ` format.
|
999
1021
|
*/
|
data/js-classes/Function.js
CHANGED
@@ -253,4 +253,84 @@
|
|
253
253
|
* argument list, curly braces, and function body.
|
254
254
|
*
|
255
255
|
* @return {String} The function as a string.
|
256
|
+
*/
|
257
|
+
|
258
|
+
// ECMAScript 5 methods
|
259
|
+
|
260
|
+
/**
|
261
|
+
* @method bind
|
262
|
+
*
|
263
|
+
* Creates a new function that, when called, has its `this` keyword set
|
264
|
+
* to the provided value, with a given sequence of arguments preceding
|
265
|
+
* any provided when the new function was called.
|
266
|
+
*
|
267
|
+
* The `bind()` function creates a new function (a bound function) with
|
268
|
+
* the same function body (internal Call attribute in ECMAScript 5
|
269
|
+
* terms) as the function it is being called on (the bound function's
|
270
|
+
* target function) with the `this` value bound to the first argument of
|
271
|
+
* `bind()`, which cannot be overridden. `bind()` also accepts leading
|
272
|
+
* default arguments to provide to the target function when the bound
|
273
|
+
* function is called. A bound function may also be constructed using
|
274
|
+
* the new operator: doing so acts as though the target function had
|
275
|
+
* instead been constructed. The provided `this` value is ignored, while
|
276
|
+
* prepended arguments are provided to the emulated function.
|
277
|
+
*
|
278
|
+
* ## Creating a bound function
|
279
|
+
*
|
280
|
+
* The simplest use of `bind()` is to make a function that, no matter
|
281
|
+
* how it is called, is called with a particular `this` value. A common
|
282
|
+
* mistake for new JavaScript programmers is to extract a method from
|
283
|
+
* an object, then to later call that function and expect it to use
|
284
|
+
* the original object as its `this` (e.g. by using that method in
|
285
|
+
* callback-based code). Without special care, however, the original
|
286
|
+
* object is usually lost. Creating a bound function from the
|
287
|
+
* function, using the original object, neatly solves `this` problem:
|
288
|
+
*
|
289
|
+
* var x = 9;
|
290
|
+
* var module = {
|
291
|
+
* x: 81,
|
292
|
+
* getX: function() { return this.x; }
|
293
|
+
* };
|
294
|
+
*
|
295
|
+
* module.getX(); // 81
|
296
|
+
*
|
297
|
+
* var getX = module.getX;
|
298
|
+
* getX(); // 9, because in this case, "this" refers to the global object
|
299
|
+
*
|
300
|
+
* // create a new function with 'this' bound to module
|
301
|
+
* var boundGetX = getX.bind(module);
|
302
|
+
* boundGetX(); // 81
|
303
|
+
*
|
304
|
+
* ## Partial functions
|
305
|
+
*
|
306
|
+
* The next simplest use of `bind()` is to make a function with
|
307
|
+
* pre-specified initial arguments. These arguments (if any) follow
|
308
|
+
* the provided this value and are then inserted at the start of the
|
309
|
+
* arguments passed to the target function, followed by the arguments
|
310
|
+
* passed to the bound function, whenever the bound function is
|
311
|
+
* called.
|
312
|
+
*
|
313
|
+
* function list() {
|
314
|
+
* return Array.prototype.slice.call(arguments);
|
315
|
+
* }
|
316
|
+
*
|
317
|
+
* var list1 = list(1, 2, 3); // [1, 2, 3]
|
318
|
+
*
|
319
|
+
* // Create a function with a preset leading argument
|
320
|
+
* var leadingZeroList = list.bind(undefined, 37);
|
321
|
+
*
|
322
|
+
* var list2 = leadingZeroList(); // [37]
|
323
|
+
* var list3 = leadingZeroList(1, 2, 3); // [37, 1, 2, 3]
|
324
|
+
*
|
325
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
326
|
+
*
|
327
|
+
* @param {Object} thisArg The value to be passed as the `this`
|
328
|
+
* parameter to the target function when the bound function is
|
329
|
+
* called. The value is ignored if the bound function is constructed
|
330
|
+
* using the new operator.
|
331
|
+
*
|
332
|
+
* @param {Mixed...} [args] Arguments to prepend to arguments provided
|
333
|
+
* to the bound function when invoking the target function.
|
334
|
+
*
|
335
|
+
* @return {Function} The bound function.
|
256
336
|
*/
|
data/js-classes/Object.js
CHANGED
@@ -401,4 +401,642 @@
|
|
401
401
|
* types[i] = [types[i].constructor, types[i] instanceof Type, types[i].toString()];
|
402
402
|
* };
|
403
403
|
* alert(types.join("\n"));
|
404
|
+
*/
|
405
|
+
|
406
|
+
// ECMAScript 5 methods
|
407
|
+
|
408
|
+
/**
|
409
|
+
* @method create
|
410
|
+
* @static
|
411
|
+
* Creates a new object with the specified prototype object and properties.
|
412
|
+
*
|
413
|
+
* ## Classical inheritance with Object.create
|
414
|
+
*
|
415
|
+
* Below is an example of how to use `Object.create` to achieve
|
416
|
+
* classical inheritance, this is for single inheritance, which is all
|
417
|
+
* that Javascript supports.
|
418
|
+
*
|
419
|
+
* //Shape - superclass
|
420
|
+
* function Shape() {
|
421
|
+
* this.x = 0;
|
422
|
+
* this.y = 0;
|
423
|
+
* }
|
424
|
+
*
|
425
|
+
* Shape.prototype.move = function(x, y) {
|
426
|
+
* this.x += x;
|
427
|
+
* this.y += y;
|
428
|
+
* console.info("Shape moved.");
|
429
|
+
* };
|
430
|
+
*
|
431
|
+
* // Rectangle - subclass
|
432
|
+
* function Rectangle() {
|
433
|
+
* Shape.call(this); //call super constructor.
|
434
|
+
* }
|
435
|
+
*
|
436
|
+
* Rectangle.prototype = Object.create(Shape.prototype);
|
437
|
+
*
|
438
|
+
* var rect = new Rectangle();
|
439
|
+
*
|
440
|
+
* rect instanceof Rectangle //true.
|
441
|
+
* rect instanceof Shape //true.
|
442
|
+
*
|
443
|
+
* rect.move(); //Outputs, "Shape moved."
|
444
|
+
*
|
445
|
+
* If you wish to inherit from multiple objects, then mixins are a possibility.
|
446
|
+
*
|
447
|
+
* function MyClass() {
|
448
|
+
* SuperClass.call(this);
|
449
|
+
* OtherSuperClass.call(this);
|
450
|
+
* }
|
451
|
+
*
|
452
|
+
* MyClass.prototype = Object.create(SuperClass.prototype); //inherit
|
453
|
+
* mixin(MyClass.prototype, OtherSuperClass.prototype); //mixin
|
454
|
+
*
|
455
|
+
* MyClass.prototype.myMethod = function() {
|
456
|
+
* // do a thing
|
457
|
+
* };
|
458
|
+
*
|
459
|
+
* The mixin function would copy the functions from the superclass
|
460
|
+
* prototype to the subclass prototype, the mixin function needs to be
|
461
|
+
* supplied by the user.
|
462
|
+
*
|
463
|
+
* ## Using `propertiesObject` argument with Object.create
|
464
|
+
*
|
465
|
+
* var o;
|
466
|
+
*
|
467
|
+
* // create an object with null as prototype
|
468
|
+
* o = Object.create(null);
|
469
|
+
*
|
470
|
+
*
|
471
|
+
* o = {};
|
472
|
+
* // is equivalent to:
|
473
|
+
* o = Object.create(Object.prototype);
|
474
|
+
*
|
475
|
+
*
|
476
|
+
* // Example where we create an object with a couple of sample properties.
|
477
|
+
* // (Note that the second parameter maps keys to *property descriptors*.)
|
478
|
+
* o = Object.create(Object.prototype, {
|
479
|
+
* // foo is a regular "value property"
|
480
|
+
* foo: { writable:true, configurable:true, value: "hello" },
|
481
|
+
* // bar is a getter-and-setter (accessor) property
|
482
|
+
* bar: {
|
483
|
+
* configurable: false,
|
484
|
+
* get: function() { return 10 },
|
485
|
+
* set: function(value) { console.log("Setting `o.bar` to", value) }
|
486
|
+
* }})
|
487
|
+
*
|
488
|
+
*
|
489
|
+
* function Constructor(){}
|
490
|
+
* o = new Constructor();
|
491
|
+
* // is equivalent to:
|
492
|
+
* o = Object.create(Constructor.prototype);
|
493
|
+
* // Of course, if there is actual initialization code in the Constructor function, the Object.create cannot reflect it
|
494
|
+
*
|
495
|
+
*
|
496
|
+
* // create a new object whose prototype is a new, empty object
|
497
|
+
* // and a adding single property 'p', with value 42
|
498
|
+
* o = Object.create({}, { p: { value: 42 } })
|
499
|
+
*
|
500
|
+
* // by default properties ARE NOT writable, enumerable or configurable:
|
501
|
+
* o.p = 24
|
502
|
+
* o.p
|
503
|
+
* //42
|
504
|
+
*
|
505
|
+
* o.q = 12
|
506
|
+
* for (var prop in o) {
|
507
|
+
* console.log(prop)
|
508
|
+
* }
|
509
|
+
* //"q"
|
510
|
+
*
|
511
|
+
* delete o.p
|
512
|
+
* //false
|
513
|
+
*
|
514
|
+
* //to specify an ES3 property
|
515
|
+
* o2 = Object.create({}, { p: { value: 42, writable: true, enumerable: true, configurable: true } });
|
516
|
+
*
|
517
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
518
|
+
*
|
519
|
+
* @param {Object} proto The object which should be the prototype of
|
520
|
+
* the newly-created object.
|
521
|
+
*
|
522
|
+
* Throws a `TypeError` exception if the `proto` parameter isn't null or
|
523
|
+
* an object.
|
524
|
+
*
|
525
|
+
* @param {Object} [propertiesObject] If specified and not undefined,
|
526
|
+
* an object whose enumerable own properties (that is, those
|
527
|
+
* properties defined upon itself and not enumerable properties along
|
528
|
+
* its prototype chain) specify property descriptors to be added to
|
529
|
+
* the newly-created object, with the corresponding property names.
|
530
|
+
*
|
531
|
+
* @return {Object} the newly created object.
|
532
|
+
*/
|
533
|
+
|
534
|
+
/**
|
535
|
+
* @method defineProperty
|
536
|
+
* @static
|
537
|
+
*
|
538
|
+
* Defines a new property directly on an object, or modifies an
|
539
|
+
* existing property on an object, and returns the object.
|
540
|
+
*
|
541
|
+
* This method allows precise addition to or modification of a
|
542
|
+
* property on an object. Normal property addition through assignment
|
543
|
+
* creates properties which show up during property enumeration
|
544
|
+
* (for...in loop or {@link Object#keys} method), whose values may be
|
545
|
+
* changed, and which may be deleted. This method allows these extra
|
546
|
+
* details to be changed from their defaults.
|
547
|
+
*
|
548
|
+
* Property descriptors present in objects come in two main flavors:
|
549
|
+
* data descriptors and accessor descriptors. A data descriptor is a
|
550
|
+
* property that has a value, which may or may not be writable. An
|
551
|
+
* accessor descriptor is a property described by a getter-setter pair
|
552
|
+
* of functions. A descriptor must be one of these two flavors; it
|
553
|
+
* cannot be both.
|
554
|
+
*
|
555
|
+
* Both data and accessor descriptor is an object with the following
|
556
|
+
* optional keys:
|
557
|
+
*
|
558
|
+
* - **configurable** True if and only if the type of this property
|
559
|
+
* descriptor may be changed and if the property may be deleted from
|
560
|
+
* the corresponding object. Defaults to false.
|
561
|
+
*
|
562
|
+
* - **enumerable** True if and only if this property shows up during
|
563
|
+
* enumeration of the properties on the corresponding
|
564
|
+
* object. Defaults to false.
|
565
|
+
*
|
566
|
+
* A data descriptor is an object with the following optional keys:
|
567
|
+
*
|
568
|
+
* - **value** The value associated with the property. Can be any
|
569
|
+
* valid JavaScript value (number, object, function, etc) Defaults
|
570
|
+
* to undefined.
|
571
|
+
*
|
572
|
+
* - **writable** True if and only if the value associated with the
|
573
|
+
* property may be changed with an assignment operator. Defaults to
|
574
|
+
* false.
|
575
|
+
*
|
576
|
+
* An accessor descriptor is an object with the following optional
|
577
|
+
* keys:
|
578
|
+
*
|
579
|
+
* - **get** A function which serves as a getter for the property, or
|
580
|
+
* undefined if there is no getter. The function return will be used
|
581
|
+
* as the value of property. Defaults to undefined.
|
582
|
+
*
|
583
|
+
* - **set** A function which serves as a setter for the property, or
|
584
|
+
* undefined if there is no setter. The function will receive as
|
585
|
+
* only argument the new value being assigned to the
|
586
|
+
* property. Defaults to undefined.
|
587
|
+
*
|
588
|
+
* Bear in mind that these options are not necessarily own properties
|
589
|
+
* so, if inherited, will be considered too. In order to ensure these
|
590
|
+
* defaults are preserved you might freeze the Object.prototype
|
591
|
+
* upfront, specify all options explicitly, or point to null as
|
592
|
+
* __proto__ property.
|
593
|
+
*
|
594
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
595
|
+
*
|
596
|
+
* @param {Object} obj The object on which to define the property.
|
597
|
+
* @param {String} prop The name of the property to be defined or modified.
|
598
|
+
* @param {Object} descriptor The descriptor for the property being
|
599
|
+
* defined or modified.
|
600
|
+
*/
|
601
|
+
|
602
|
+
/**
|
603
|
+
* @method defineProperties
|
604
|
+
* @static
|
605
|
+
*
|
606
|
+
* Defines new or modifies existing properties directly on an object,
|
607
|
+
* returning the object.
|
608
|
+
*
|
609
|
+
* In essence, it defines all properties corresponding to the
|
610
|
+
* enumerable own properties of props on the object.
|
611
|
+
*
|
612
|
+
* Object.defineProperties(obj, {
|
613
|
+
* "property1": {
|
614
|
+
* value: true,
|
615
|
+
* writable: true
|
616
|
+
* },
|
617
|
+
* "property2": {
|
618
|
+
* value: "Hello",
|
619
|
+
* writable: false
|
620
|
+
* }
|
621
|
+
* // etc. etc.
|
622
|
+
* });
|
623
|
+
*
|
624
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
625
|
+
*
|
626
|
+
* @param {Object} obj The object on which to define or modify properties.
|
627
|
+
* @param {Object} props An object whose own enumerable properties
|
628
|
+
* constitute descriptors for the properties to be defined or
|
629
|
+
* modified.
|
630
|
+
*/
|
631
|
+
|
632
|
+
/**
|
633
|
+
* @method getOwnPropertyDescriptor
|
634
|
+
* @static
|
635
|
+
*
|
636
|
+
* Returns a property descriptor for an own property (that is, one
|
637
|
+
* directly present on an object, not present by dint of being along
|
638
|
+
* an object's prototype chain) of a given object.
|
639
|
+
*
|
640
|
+
* This method permits examination of the precise description of a
|
641
|
+
* property. A property in JavaScript consists of a string-valued name
|
642
|
+
* and a property descriptor. Further information about property
|
643
|
+
* descriptor types and their attributes can be found in
|
644
|
+
* {@link Object#defineProperty}.
|
645
|
+
*
|
646
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
647
|
+
*
|
648
|
+
* @param {Object} obj The object in which to look for the property.
|
649
|
+
* @param {String} prop The name of the property whose description is
|
650
|
+
* to be retrieved.
|
651
|
+
*
|
652
|
+
* A property descriptor is a record with some of the following
|
653
|
+
* attributes:
|
654
|
+
*
|
655
|
+
* - **value** The value associated with the property (data
|
656
|
+
* descriptors only).
|
657
|
+
*
|
658
|
+
* - **writable** True if and only if the value associated with
|
659
|
+
* the property may be changed (data descriptors only).
|
660
|
+
*
|
661
|
+
* - **get** A function which serves as a getter for the property,
|
662
|
+
* or undefined if there is no getter (accessor descriptors only).
|
663
|
+
*
|
664
|
+
* - **set** A function which serves as a setter for the property,
|
665
|
+
* or undefined if there is no setter (accessor descriptors only).
|
666
|
+
*
|
667
|
+
* - **configurable** true if and only if the type of this property
|
668
|
+
* descriptor may be changed and if the property may be deleted
|
669
|
+
* from the corresponding object.
|
670
|
+
*
|
671
|
+
* - **enumerable** true if and only if this property shows up
|
672
|
+
* during enumeration of the properties on the corresponding object.
|
673
|
+
*
|
674
|
+
* @return {Mixed} Value of the property descriptor.
|
675
|
+
*/
|
676
|
+
|
677
|
+
/**
|
678
|
+
* @method keys
|
679
|
+
* @static
|
680
|
+
*
|
681
|
+
* Returns an array of a given object's own enumerable properties, in
|
682
|
+
* the same order as that provided by a for-in loop (the difference
|
683
|
+
* being that a for-in loop enumerates properties in the prototype
|
684
|
+
* chain as well).
|
685
|
+
*
|
686
|
+
* Returns an array whose elements are strings corresponding to the
|
687
|
+
* enumerable properties found directly upon object. The ordering of
|
688
|
+
* the properties is the same as that given by looping over the
|
689
|
+
* properties of the object manually.
|
690
|
+
*
|
691
|
+
* var arr = ["a", "b", "c"];
|
692
|
+
* alert(Object.keys(arr)); // will alert "0,1,2"
|
693
|
+
*
|
694
|
+
* // array like object
|
695
|
+
* var obj = { 0 : "a", 1 : "b", 2 : "c"};
|
696
|
+
* alert(Object.keys(obj)); // will alert "0,1,2"
|
697
|
+
*
|
698
|
+
* // getFoo is property which isn't enumerable
|
699
|
+
* var my_obj = Object.create({}, { getFoo : { value : function () { return this.foo } } });
|
700
|
+
* my_obj.foo = 1;
|
701
|
+
*
|
702
|
+
* alert(Object.keys(my_obj)); // will alert only foo
|
703
|
+
*
|
704
|
+
* If you want all properties, even the not enumerable, see
|
705
|
+
* {@link Object#getOwnPropertyNames}.
|
706
|
+
*
|
707
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
708
|
+
*
|
709
|
+
* @param {Object} obj The object whose enumerable own properties are
|
710
|
+
* to be returned.
|
711
|
+
* @return {String[]} Array of property names.
|
712
|
+
*/
|
713
|
+
|
714
|
+
/**
|
715
|
+
* @method getOwnPropertyNames
|
716
|
+
* @static
|
717
|
+
*
|
718
|
+
* Returns an array of all properties (enumerable or not) found
|
719
|
+
* directly upon a given object.
|
720
|
+
*
|
721
|
+
* Rreturns an array whose elements are strings corresponding to the
|
722
|
+
* enumerable and non-enumerable properties found directly upon
|
723
|
+
* obj. The ordering of the enumerable properties in the array is
|
724
|
+
* consistent with the ordering exposed by a for...in loop (or by
|
725
|
+
* {@link Object#keys}) over the properties of the object. The
|
726
|
+
* ordering of the non-enumerable properties in the array, and among
|
727
|
+
* the enumerable properties, is not defined.
|
728
|
+
*
|
729
|
+
* var arr = ["a", "b", "c"];
|
730
|
+
* print(Object.getOwnPropertyNames(arr).sort()); // prints "0,1,2,length"
|
731
|
+
*
|
732
|
+
* // Array-like object
|
733
|
+
* var obj = { 0: "a", 1: "b", 2: "c"};
|
734
|
+
* print(Object.getOwnPropertyNames(obj).sort()); // prints "0,1,2"
|
735
|
+
*
|
736
|
+
* // Printing property names and values using Array.forEach
|
737
|
+
* Object.getOwnPropertyNames(obj).forEach(function(val, idx, array) {
|
738
|
+
* print(val + " -> " + obj[val]);
|
739
|
+
* });
|
740
|
+
* // prints
|
741
|
+
* // 0 -> a
|
742
|
+
* // 1 -> b
|
743
|
+
* // 2 -> c
|
744
|
+
*
|
745
|
+
* // non-enumerable property
|
746
|
+
* var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; }, enumerable: false } });
|
747
|
+
* my_obj.foo = 1;
|
748
|
+
*
|
749
|
+
* print(Object.getOwnPropertyNames(my_obj).sort()); // prints "foo, getFoo"
|
750
|
+
*
|
751
|
+
* If you want only the enumerable properties, see {@link Object#keys}
|
752
|
+
* or use a for...in loop (although note that this will return
|
753
|
+
* enumerable properties not found directly upon that object but also
|
754
|
+
* along the prototype chain for the object unless the latter is
|
755
|
+
* filtered with {@link #hasOwnProperty}).
|
756
|
+
*
|
757
|
+
* Items on the prototype chain are not listed:
|
758
|
+
*
|
759
|
+
* function ParentClass () {
|
760
|
+
* }
|
761
|
+
* ParentClass.prototype.inheritedMethod = function () {
|
762
|
+
* };
|
763
|
+
*
|
764
|
+
* function ChildClass () {
|
765
|
+
* this.prop = 5;
|
766
|
+
* this.method = function () {};
|
767
|
+
* }
|
768
|
+
* ChildClass.prototype = new ParentClass;
|
769
|
+
* ChildClass.prototype.prototypeMethod = function () {
|
770
|
+
* };
|
771
|
+
*
|
772
|
+
* alert(
|
773
|
+
* Object.getOwnPropertyNames(
|
774
|
+
* new ChildClass() // ["prop", "method"]
|
775
|
+
* )
|
776
|
+
* )
|
777
|
+
*
|
778
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
779
|
+
*
|
780
|
+
* @param {Object} obj The object whose enumerable and non-enumerable
|
781
|
+
* own properties are to be returned.
|
782
|
+
* @return {String[]} Array of property names.
|
783
|
+
*/
|
784
|
+
|
785
|
+
/**
|
786
|
+
* @method getPrototypeOf
|
787
|
+
* @static
|
788
|
+
*
|
789
|
+
* Returns the prototype (i.e. the internal `[[Prototype]]`) of the
|
790
|
+
* specified object.
|
791
|
+
*
|
792
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
793
|
+
*
|
794
|
+
* @param {Object} object The object whose prototype is to be returned.
|
795
|
+
* Throws a TypeError exception if this parameter isn't an Object.
|
796
|
+
*
|
797
|
+
* @return {Object} the prototype
|
798
|
+
*/
|
799
|
+
|
800
|
+
/**
|
801
|
+
* @method preventExtensions
|
802
|
+
* @static
|
803
|
+
*
|
804
|
+
* Prevents new properties from ever being added to an object
|
805
|
+
* (i.e. prevents future extensions to the object).
|
806
|
+
*
|
807
|
+
* An object is extensible if new properties can be added to it.
|
808
|
+
* `preventExtensions` marks an object as no longer extensible, so that
|
809
|
+
* it will never have properties beyond the ones it had at the time it
|
810
|
+
* was marked as non-extensible. Note that the properties of a
|
811
|
+
* non-extensible object, in general, may still be deleted. Attempting
|
812
|
+
* to add new properties to a non-extensible object will fail, either
|
813
|
+
* silently or by throwing a TypeError (most commonly, but not
|
814
|
+
* exclusively, when in strict mode).
|
815
|
+
*
|
816
|
+
* It only prevents addition of own properties. Properties can still
|
817
|
+
* be added to the object prototype.
|
818
|
+
*
|
819
|
+
* If there is a way to turn an extensible object to a non-extensible
|
820
|
+
* one, there is no way to do the opposite in ECMAScript 5
|
821
|
+
*
|
822
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
823
|
+
*
|
824
|
+
* @param {Object} obj The object which should be made non-extensible.
|
825
|
+
*/
|
826
|
+
|
827
|
+
/**
|
828
|
+
* @method isExtensible
|
829
|
+
* @static
|
830
|
+
*
|
831
|
+
* Determines if an object is extensible (whether it can have new
|
832
|
+
* properties added to it).
|
833
|
+
*
|
834
|
+
* Objects are extensible by default: they can have new properties
|
835
|
+
* added to them, and can be modified. An object can be marked as
|
836
|
+
* non-extensible using {@link Object#preventExtensions},
|
837
|
+
* {@link Object#seal}, or {@link Object#freeze}.
|
838
|
+
*
|
839
|
+
* // New objects are extensible.
|
840
|
+
* var empty = {};
|
841
|
+
* assert(Object.isExtensible(empty) === true);
|
842
|
+
*
|
843
|
+
* // ...but that can be changed.
|
844
|
+
* Object.preventExtensions(empty);
|
845
|
+
* assert(Object.isExtensible(empty) === false);
|
846
|
+
*
|
847
|
+
* // Sealed objects are by definition non-extensible.
|
848
|
+
* var sealed = Object.seal({});
|
849
|
+
* assert(Object.isExtensible(sealed) === false);
|
850
|
+
*
|
851
|
+
* // Frozen objects are also by definition non-extensible.
|
852
|
+
* var frozen = Object.freeze({});
|
853
|
+
* assert(Object.isExtensible(frozen) === false);
|
854
|
+
*
|
855
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
856
|
+
*
|
857
|
+
* @param {Object} obj The object which should be checked.
|
858
|
+
* @return {Boolean} True when object is extensible.
|
859
|
+
*/
|
860
|
+
|
861
|
+
/**
|
862
|
+
* @method seal
|
863
|
+
* @static
|
864
|
+
*
|
865
|
+
* Seals an object, preventing new properties from being added to it
|
866
|
+
* and marking all existing properties as non-configurable. Values of
|
867
|
+
* present properties can still be changed as long as they are
|
868
|
+
* writable.
|
869
|
+
*
|
870
|
+
* By default, objects are extensible (new properties can be added to
|
871
|
+
* them). Sealing an object prevents new properties from being added
|
872
|
+
* and marks all existing properties as non-configurable. This has the
|
873
|
+
* effect of making the set of properties on the object fixed and
|
874
|
+
* immutable. Making all properties non-configurable also prevents
|
875
|
+
* them from being converted from data properties to accessor
|
876
|
+
* properties and vice versa, but it does not prevent the values of
|
877
|
+
* data properties from being changed. Attempting to delete or add
|
878
|
+
* properties to a sealed object, or to convert a data property to
|
879
|
+
* accessor or vice versa, will fail, either silently or by throwing a
|
880
|
+
* TypeError (most commonly, although not exclusively, when in strict
|
881
|
+
* mode code).
|
882
|
+
*
|
883
|
+
* The prototype chain remains untouched.
|
884
|
+
*
|
885
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
886
|
+
*
|
887
|
+
* @param {Object} obj The object which should be sealed.
|
888
|
+
*/
|
889
|
+
|
890
|
+
/**
|
891
|
+
* @method isSealed
|
892
|
+
* @static
|
893
|
+
*
|
894
|
+
* Determines if an object is sealed.
|
895
|
+
*
|
896
|
+
* An object is sealed if it is non-extensible and if all its
|
897
|
+
* properties are non-configurable and therefore not removable (but
|
898
|
+
* not necessarily non-writable).
|
899
|
+
*
|
900
|
+
* // Objects aren't sealed by default.
|
901
|
+
* var empty = {};
|
902
|
+
* assert(Object.isSealed(empty) === false);
|
903
|
+
*
|
904
|
+
* // If you make an empty object non-extensible, it is vacuously sealed.
|
905
|
+
* Object.preventExtensions(empty);
|
906
|
+
* assert(Object.isSealed(empty) === true);
|
907
|
+
*
|
908
|
+
* // The same is not true of a non-empty object, unless its properties are all non-configurable.
|
909
|
+
* var hasProp = { fee: "fie foe fum" };
|
910
|
+
* Object.preventExtensions(hasProp);
|
911
|
+
* assert(Object.isSealed(hasProp) === false);
|
912
|
+
*
|
913
|
+
* // But make them all non-configurable and the object becomes sealed.
|
914
|
+
* Object.defineProperty(hasProp, "fee", { configurable: false });
|
915
|
+
* assert(Object.isSealed(hasProp) === true);
|
916
|
+
*
|
917
|
+
* // The easiest way to seal an object, of course, is Object.seal.
|
918
|
+
* var sealed = {};
|
919
|
+
* Object.seal(sealed);
|
920
|
+
* assert(Object.isSealed(sealed) === true);
|
921
|
+
*
|
922
|
+
* // A sealed object is, by definition, non-extensible.
|
923
|
+
* assert(Object.isExtensible(sealed) === false);
|
924
|
+
*
|
925
|
+
* // A sealed object might be frozen, but it doesn't have to be.
|
926
|
+
* assert(Object.isFrozen(sealed) === true); // all properties also non-writable
|
927
|
+
*
|
928
|
+
* var s2 = Object.seal({ p: 3 });
|
929
|
+
* assert(Object.isFrozen(s2) === false); // "p" is still writable
|
930
|
+
*
|
931
|
+
* var s3 = Object.seal({ get p() { return 0; } });
|
932
|
+
* assert(Object.isFrozen(s3) === true); // only configurability matters for accessor properties
|
933
|
+
*
|
934
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
935
|
+
*
|
936
|
+
* @param {Object} obj The object which should be checked.
|
937
|
+
* @return {Boolean} True if the object is sealed, otherwise false.
|
938
|
+
*/
|
939
|
+
|
940
|
+
/**
|
941
|
+
* @method freeze
|
942
|
+
* @static
|
943
|
+
*
|
944
|
+
* Freezes an object: that is, prevents new properties from being
|
945
|
+
* added to it; prevents existing properties from being removed; and
|
946
|
+
* prevents existing properties, or their enumerability,
|
947
|
+
* configurability, or writability, from being changed. In essence the
|
948
|
+
* object is made effectively immutable. The method returns the object
|
949
|
+
* being frozen.
|
950
|
+
*
|
951
|
+
* Nothing can be added to or removed from the properties set of a
|
952
|
+
* frozen object. Any attempt to do so will fail, either silently or
|
953
|
+
* by throwing a TypeError exception (most commonly, but not
|
954
|
+
* exclusively, when in strict mode).
|
955
|
+
*
|
956
|
+
* Values cannot be changed for data properties. Accessor properties
|
957
|
+
* (getters and setters) work the same (and still give the illusion
|
958
|
+
* that you are changing the value). Note that values that are objects
|
959
|
+
* can still be modified, unless they are also frozen.
|
960
|
+
*
|
961
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
962
|
+
*
|
963
|
+
* @param {Object} obj The object to freeze.
|
964
|
+
*/
|
965
|
+
|
966
|
+
/**
|
967
|
+
* @method isFrozen
|
968
|
+
* @static
|
969
|
+
*
|
970
|
+
* Determines if an object is frozen.
|
971
|
+
*
|
972
|
+
* An object is frozen if and only if it is not extensible, all its
|
973
|
+
* properties are non-configurable, and all its data properties (that
|
974
|
+
* is, properties which are not accessor properties with getter or
|
975
|
+
* setter components) are non-writable.
|
976
|
+
*
|
977
|
+
* // A new object is extensible, so it is not frozen.
|
978
|
+
* assert(Object.isFrozen({}) === false);
|
979
|
+
*
|
980
|
+
* // An empty object which is not extensible is vacuously frozen.
|
981
|
+
* var vacuouslyFrozen = Object.preventExtensions({});
|
982
|
+
* assert(Object.isFrozen(vacuouslyFrozen) === true);
|
983
|
+
*
|
984
|
+
* // A new object with one property is also extensible, ergo not frozen.
|
985
|
+
* var oneProp = { p: 42 };
|
986
|
+
* assert(Object.isFrozen(oneProp) === false);
|
987
|
+
*
|
988
|
+
* // Preventing extensions to the object still doesn't make it frozen,
|
989
|
+
* // because the property is still configurable (and writable).
|
990
|
+
* Object.preventExtensions(oneProp);
|
991
|
+
* assert(Object.isFrozen(oneProp) === false);
|
992
|
+
*
|
993
|
+
* // ...but then deleting that property makes the object vacuously frozen.
|
994
|
+
* delete oneProp.p;
|
995
|
+
* assert(Object.isFrozen(oneProp) === true);
|
996
|
+
*
|
997
|
+
* // A non-extensible object with a non-writable but still configurable property is not frozen.
|
998
|
+
* var nonWritable = { e: "plep" };
|
999
|
+
* Object.preventExtensions(nonWritable);
|
1000
|
+
* Object.defineProperty(nonWritable, "e", { writable: false }); // make non-writable
|
1001
|
+
* assert(Object.isFrozen(nonWritable) === false);
|
1002
|
+
*
|
1003
|
+
* // Changing that property to non-configurable then makes the object frozen.
|
1004
|
+
* Object.defineProperty(nonWritable, "e", { configurable: false }); // make non-configurable
|
1005
|
+
* assert(Object.isFrozen(nonWritable) === true);
|
1006
|
+
*
|
1007
|
+
* // A non-extensible object with a non-configurable but still writable property also isn't frozen.
|
1008
|
+
* var nonConfigurable = { release: "the kraken!" };
|
1009
|
+
* Object.preventExtensions(nonConfigurable);
|
1010
|
+
* Object.defineProperty(nonConfigurable, "release", { configurable: false });
|
1011
|
+
* assert(Object.isFrozen(nonConfigurable) === false);
|
1012
|
+
*
|
1013
|
+
* // Changing that property to non-writable then makes the object frozen.
|
1014
|
+
* Object.defineProperty(nonConfigurable, "release", { writable: false });
|
1015
|
+
* assert(Object.isFrozen(nonConfigurable) === true);
|
1016
|
+
*
|
1017
|
+
* // A non-extensible object with a configurable accessor property isn't frozen.
|
1018
|
+
* var accessor = { get food() { return "yum"; } };
|
1019
|
+
* Object.preventExtensions(accessor);
|
1020
|
+
* assert(Object.isFrozen(accessor) === false);
|
1021
|
+
*
|
1022
|
+
* // ...but make that property non-configurable and it becomes frozen.
|
1023
|
+
* Object.defineProperty(accessor, "food", { configurable: false });
|
1024
|
+
* assert(Object.isFrozen(accessor) === true);
|
1025
|
+
*
|
1026
|
+
* // But the easiest way for an object to be frozen is if Object.freeze has been called on it.
|
1027
|
+
* var frozen = { 1: 81 };
|
1028
|
+
* assert(Object.isFrozen(frozen) === false);
|
1029
|
+
* Object.freeze(frozen);
|
1030
|
+
* assert(Object.isFrozen(frozen) === true);
|
1031
|
+
*
|
1032
|
+
* // By definition, a frozen object is non-extensible.
|
1033
|
+
* assert(Object.isExtensible(frozen) === false);
|
1034
|
+
*
|
1035
|
+
* // Also by definition, a frozen object is sealed.
|
1036
|
+
* assert(Object.isSealed(frozen) === true);
|
1037
|
+
*
|
1038
|
+
* **NOTE:** This method is part of the ECMAScript 5 standard.
|
1039
|
+
*
|
1040
|
+
* @param {Object} obj The object which should be checked.
|
1041
|
+
* @return {Boolean} True if the object is frozen, otherwise false.
|
404
1042
|
*/
|