| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- function globalFixedFunction1() {
- WScript.Echo("globalFixedFunction1: original");
- }
- var globalFixedFunction2 = function () {
- WScript.Echo("globalFixedFunction2: original");
- }
- function testGlobal() {
- globalFixedFunction1();
- globalFixedFunction2();
- }
- WScript.Echo("Testing the global object:");
- testGlobal();
- testGlobal();
- globalFixedFunction1 = function () {
- WScript.Echo("globalFixedFunction1: overwritten");
- }
- globalFixedFunction2 = function () {
- WScript.Echo("globalFixedFunction2: overwritten");
- }
- testGlobal();
- WScript.Echo();
- WScript.Echo("Testing object literal:");
- var objectLiteral = {
- unique1: 0,
- x: 0,
- y: 1,
- add: function () {
- return (this.x + this.y) + " (original)";
- },
- subtract: function () {
- return (this.x - this.y) + " (original)";
- }
- }
- function testObjectLiteral() {
- WScript.Echo("x + y = " + objectLiteral.add());
- WScript.Echo("x - y = " + objectLiteral.subtract());
- }
- testObjectLiteral();
- testObjectLiteral();
- objectLiteral.add = function () {
- return (this.x + this.y) + " (overwritten)";
- }
- testObjectLiteral();
- WScript.Echo();
- WScript.Echo("Testing Object.defineProperty with accessors:");
- var object = {};
- Object.defineProperty(object, "x", { get: function() { return "0 (original)"; }, configurable: true });
- function testObjectDefineProperty() {
- WScript.Echo("x = " + object.x);
- }
- testObjectDefineProperty();
- testObjectDefineProperty();
- Object.defineProperty(object, "x", { get: function () { return "1 (overwritten)"; } });
- testObjectDefineProperty();
- WScript.Echo();
- WScript.Echo("Testing the Math object:");
- Math.identity = function (value) {
- return value;
- }
- function testMathObject() {
- WScript.Echo("Math.sin(Math.PI) = " + Math.sin(Math.PI));
- WScript.Echo("Math.identity(Math.PI) = " + Math.identity(Math.PI));
- }
- testMathObject();
- testMathObject();
- Math.identity = function (value) {
- return -value;
- }
- testMathObject();
- Math.sin = function (value) {
- return -value;
- }
- testMathObject();
- WScript.Echo();
- WScript.Echo("Testing the Object constructor:");
- Object.identity = function (value) {
- return value;
- }
- function testObjectConstructor() {
- var o = {};
- Object.seal(o);
- WScript.Echo("Object.identity(o) = " + Object.identity(o));
- WScript.Echo("Object.isSealed(o) = " + Object.isSealed(o));
- }
- testObjectConstructor();
- testObjectConstructor();
- Object.identity = function (value) {
- return "I don't know you anymore...";
- }
- testObjectConstructor();
- Object.seal = function (object) {
- return false;
- }
- testObjectConstructor();
- Object.isSealed = function (object) {
- return "With the magic of JavaScript I pronounce you sealed!";
- }
- testObjectConstructor();
- WScript.Echo();
|