JavaScript Feature Reference: defineProperty() Method Web Browser Support Test

Last reviewed/updated: 28 Apr 2018 | Published: 12 Dec 2017 | Status: Active
Web browser support: Internet Explorer 10+, Edge 12+, Firefox 6+, Chrome 30+, Opera 17+

1. Introduction

In this web page there are two web browser JavaScript feature support tests; 1.) a feature implementation test, and 2.) a feature capability test. First, the implementation test is run. The implementation test determines if the web browser recognizes the JavaScript defineProperty() method. The implementation test is a simple test for the presence of web browser support, and a definitive test for the absence of web browser support. If the web browser does not recognize the JavaScript defineProperty() method, the testing is stopped and the implementation test reports: Fail (no support): The web browser does not recognize the JavaScript defineProperty() method. The web browser does not support the JavaScript defineProperty() method.

If the web browser recognizes the JavaScript defineProperty() method, the capability test is run. The capability test determines if the web browser's implementation of the JavaScript defineProperty() method includes support for at least one defineProperty() method capability. The capability test is a more definitive, albeit not an all inclusive, test for the presence of web browser support. If the web browser's implementation of the JavaScript defineProperty() method includes support for the tested capability, the capability test reports: Pass (at least partial/possibly full support): The web browser recognizes the JavaScript defineProperty() method, and supports at least one defineProperty() method capability. The web browser at least partially/possibly fully supports the JavaScript defineProperty() method. Positive determination of full web browser support is beyond the scope of this test. If the web browser's implementation of the JavaScript defineProperty() method does not include support for the tested capability, the capability test reports: Pass/Fail (partial support): The web browser recognizes the JavaScript defineProperty() method, but does not support at least one defineProperty() method capability. The web browser partially supports the JavaScript defineProperty() method.

The web browser support test source code is shown in Section 2.1. The web browser support test source code is run in Section 2.2, which shows the web browser support test result.

1.1. defineProperty() Method Web Browser Support

Pass (at least partial/possibly full support): IE9+, ED12+, FF4+, SF5+, CH5+, OP11.60+.

1.2. Abbreviations

  • IE = Internet Explorer.
  • ED = Edge = EdgeHTML rendering engine (ED12+) and/or Edge browser (ED20+).
  • FF = Firefox.
  • SF = Safari.
  • CH = Chrome.
  • OP = Opera.

2. defineProperty() Method Web Browser Support Test

2.1. Web Browser Support Test Source Code

<p id='testId'><b>Fail</b> (no support): The web browser does not recognize the JavaScript <code>defineProperty()</code> method. The web browser does not support the JavaScript <code>defineProperty()</code> method.</p><!-- Hard code Fail because web browser no support error stops JavaScript execution. -->

<script>
if (Object.defineProperty){
 var element = document.getElementById("testId");
 function CustomConstructor(){
  this.propertyOne = "propertyOne value"; // Data property. Here, property writable, enumerable, and configurable attributes default to boolean true.
  this.propertyFour = "propertyFour value as propertyThree getter function return value";
  this.propertyFive = "propertyFive value appended by propertyThree setter function";
 }
 var objectViaCustomConstructor = new CustomConstructor();
 Object.defineProperty(objectViaCustomConstructor, "propertyOne", { // Change objectViaCustomConstructor.propertyOne value attribute value. IE8 error: Object doesn't support this action.
  value: "new propertyOne value"
 });
 Object.defineProperty(objectViaCustomConstructor, "propertyTwo", { // Create objectViaCustomConstructor.propertyTwo data property. Here, property writable, enumerable, and configurable attributes default to boolean false.
  value: "propertyTwo value"
 });
 Object.defineProperty(objectViaCustomConstructor, "propertyThree", { // Create objectViaCustomConstructor.propertyThree accessor property. Here, property enumerable and configurable attributes default to boolean false.
  get: function(){
   return this.propertyFour;
  },
  set: function(value){
   this.propertyFive += value;
  }
 });
 objectViaCustomConstructor.propertyThree = " passed value"; // "propertyFive value appended by propertyThree setter function passed value".
 var objectLiteral = {
  propertyOne: "propertyOne value", // Data property. Here, property writable, enumerable, and configurable attributes default to boolean true.
  propertyFour: "propertyFour value as propertyThree getter function return value",
  propertyFive: "propertyFive value appended by propertyThree setter function"
 };
 Object.defineProperty(objectLiteral, "propertyOne", { // Change objectLiteral.propertyOne value attribute value.
  value: "new propertyOne value"
 });
 Object.defineProperty(objectLiteral, "propertyTwo", { // Create objectLiteral.propertyTwo data property. Here, property writable, enumerable, and configurable attributes default to boolean false.
  value: "propertyTwo value"
 });
 Object.defineProperty(objectLiteral, "propertyThree", { // Create objectLiteral.propertyThree accessor property. Here, property enumerable and configurable attributes default to boolean false.
  get: function(){
   return this.propertyFour;
  },
  set: function(value){
   this.propertyFive += value;
  }
 });
 objectLiteral.propertyThree = " passed value"; // "propertyFive value appended by propertyThree setter function passed value".
 var objectViaCustomConstructorPropertyOneDescriptor = Object.getOwnPropertyDescriptor(objectViaCustomConstructor, "propertyOne");
 var objectViaCustomConstructorPropertyTwoDescriptor = Object.getOwnPropertyDescriptor(objectViaCustomConstructor, "propertyTwo");
 var objectViaCustomConstructorPropertyThreeDescriptor = Object.getOwnPropertyDescriptor(objectViaCustomConstructor, "propertyThree");
 var objectLiteralPropertyOneDescriptor = Object.getOwnPropertyDescriptor(objectLiteral, "propertyOne");
 var objectLiteralPropertyTwoDescriptor = Object.getOwnPropertyDescriptor(objectLiteral, "propertyTwo");
 var objectLiteralPropertyThreeDescriptor = Object.getOwnPropertyDescriptor(objectLiteral, "propertyThree");
 if ((objectViaCustomConstructor.propertyOne === "new propertyOne value") && (objectViaCustomConstructor.propertyTwo === "propertyTwo value") && (objectViaCustomConstructor.propertyThree === "propertyFour value as propertyThree getter function return value") && (objectViaCustomConstructor.propertyFive === "propertyFive value appended by propertyThree setter function passed value") && objectViaCustomConstructorPropertyOneDescriptor.writable && !objectViaCustomConstructorPropertyTwoDescriptor.enumerable && !objectViaCustomConstructorPropertyThreeDescriptor.configurable && (objectLiteral.propertyOne === "new propertyOne value") && (objectLiteral.propertyTwo === "propertyTwo value") && (objectLiteral.propertyThree === "propertyFour value as propertyThree getter function return value") && (objectLiteral.propertyFive === "propertyFive value appended by propertyThree setter function passed value") && objectLiteralPropertyOneDescriptor.writable && !objectLiteralPropertyTwoDescriptor.enumerable && !objectLiteralPropertyThreeDescriptor.configurable){
  element.innerHTML = "<b>Pass</b> (at least partial/possibly full support): The web browser recognizes the JavaScript <code>defineProperty()</code> method, and supports at least one <code>defineProperty()</code> method capability. The web browser at least partially/possibly fully supports the JavaScript <code>defineProperty()</code> method. Positive determination of full web browser support is beyond the scope of this test.";
 } else {
  element.innerHTML = "<b>Pass/Fail</b> (partial support): The web browser recognizes the JavaScript <code>defineProperty()</code> method, but does not support at least one <code>defineProperty()</code> method capability. The web browser partially supports the JavaScript <code>defineProperty()</code> method.";
 }
}
</script>

2.2. Web Browser Support Test Result

Fail (no support): The web browser does not recognize the JavaScript defineProperty() method. The web browser does not support the JavaScript defineProperty() method.


3. Resources And Additional Information