JavaScript Feature Reference: class Syntax Web Browser Support Test

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

1. Introduction

In this web page there is one web browser JavaScript feature support test: a feature implementation test. The implementation test determines if the web browser recognizes the JavaScript class syntax. 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 class syntax, the implementation test reports: Fail (no support): The web browser does not recognize the JavaScript class syntax. The web browser does not support the JavaScript class syntax. If the web browser recognizes the JavaScript class syntax, the implementation test reports: Pass (at least partial/possibly full support): The web browser recognizes the JavaScript class syntax. The web browser at least partially/possibly fully supports the JavaScript class syntax. Positive determination of full web browser support is beyond the scope of this test.

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. class Syntax Web Browser Support

  • Pass (at least partial/possibly full support): ED13+, FF45+, CH49+, OP36+.
  • Fail (no support): IE11-, SF5.1.7-.

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. class Syntax 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>class</code> syntax. The web browser does not support the JavaScript <code>class</code> syntax.</p><!-- Hard code Fail because web browser no support error stops JavaScript execution. -->

<script>
class ClassDeclaration { // Class definition (not hoisted) using class declaration syntax.
 constructor(param){ // Class constructor() method (optional). Recommend define all own properties inside class constructor() method.
  this.ownPropertyOne = param; // objectViaClassDeclaration ownPropertyOne.
 }
 conciseMethod(){ // objectViaClassDeclaration prototype property. Class methods use concise method syntax and are not enumerable (ie, propertyIsEnumerable() method returns false).
  return this.ownPropertyOne;
 }
}
ClassDeclaration.prototype.prototypePropertyOne = "prototypePropertyOne value"; // ClassDeclaration prototypePropertyOne.
ClassDeclaration.prototype.prototypePropertyTwo = function(){ // ClassDeclaration prototypePropertyTwo.
 return "prototypePropertyTwo return value";
};
var objectViaClassDeclaration = new ClassDeclaration("argument"); // Instantiate object by calling class definition with new operator (required). Arguments are passed to class constructor() method.
var callObjectViaClassDeclarationConciseMethod = objectViaClassDeclaration.conciseMethod();
var callObjectViaClassDeclarationPrototypePropertyTwo = objectViaClassDeclaration.prototypePropertyTwo();
var ClassExpression = class { // Class definition (not hoisted) using class expression syntax.
 constructor(param){ // Class constructor() method (optional). Recommend define all own properties inside class constructor() method.
  this.ownPropertyOne = param; // objectViaClassExpression ownPropertyOne.
 }
 conciseMethod(){ // objectViaClassExpression prototype property. Class methods use concise method syntax and are not enumerable (ie, propertyIsEnumerable() method returns false).
  return this.ownPropertyOne;
 }
}
ClassExpression.prototype.prototypePropertyOne = "prototypePropertyOne value"; // ClassExpression prototypePropertyOne.
ClassExpression.prototype.prototypePropertyTwo = function(){ // ClassExpression prototypePropertyTwo.
 return "prototypePropertyTwo return value";
};
var objectViaClassExpression = new ClassExpression("argument"); // Instantiate object by calling class definition with new operator (required). Arguments are passed to class constructor() method.
var callObjectViaClassExpressionConciseMethod = objectViaClassExpression.conciseMethod();
var callObjectViaClassExpressionPrototypePropertyTwo = objectViaClassExpression.prototypePropertyTwo();
if ((typeof ClassDeclaration === "function") && ClassDeclaration instanceof Function && ClassDeclaration instanceof Object && (typeof objectViaClassDeclaration === "object") && objectViaClassDeclaration instanceof ClassDeclaration && !(objectViaClassDeclaration instanceof Function) && objectViaClassDeclaration instanceof Object && (objectViaClassDeclaration.ownPropertyOne === "argument") && (callObjectViaClassDeclarationConciseMethod === "argument") && (objectViaClassDeclaration.prototypePropertyOne === "prototypePropertyOne value") && (callObjectViaClassDeclarationPrototypePropertyTwo === "prototypePropertyTwo return value") && objectViaClassDeclaration.hasOwnProperty("ownPropertyOne") && !objectViaClassDeclaration.hasOwnProperty("conciseMethod") && !objectViaClassDeclaration.hasOwnProperty("prototypePropertyOne") && !objectViaClassDeclaration.hasOwnProperty("prototypePropertyTwo") && (Object.getPrototypeOf(objectViaClassDeclaration).ownPropertyOne === undefined) && (typeof ClassDeclaration.prototype.ownPropertyOne === "undefined") && (typeof ClassDeclaration.prototype.conciseMethod === "function") && (typeof ClassDeclaration.prototype.prototypePropertyOne === "string") && (typeof ClassDeclaration.prototype.prototypePropertyTwo === "function") && objectViaClassDeclaration.propertyIsEnumerable("ownPropertyOne") && !objectViaClassDeclaration.propertyIsEnumerable("conciseMethod") && !objectViaClassDeclaration.propertyIsEnumerable("prototypePropertyOne") && !objectViaClassDeclaration.propertyIsEnumerable("prototypePropertyTwo") && (typeof ClassExpression === "function") && ClassExpression instanceof Function && ClassExpression instanceof Object && (typeof objectViaClassExpression === "object") && objectViaClassExpression instanceof ClassExpression && !(objectViaClassExpression instanceof Function) && objectViaClassExpression instanceof Object && (objectViaClassExpression.ownPropertyOne === "argument") && (callObjectViaClassExpressionConciseMethod === "argument") && (objectViaClassExpression.prototypePropertyOne === "prototypePropertyOne value") && (callObjectViaClassExpressionPrototypePropertyTwo === "prototypePropertyTwo return value") && objectViaClassExpression.hasOwnProperty("ownPropertyOne") && !objectViaClassExpression.hasOwnProperty("conciseMethod") && !objectViaClassExpression.hasOwnProperty("prototypePropertyOne") && !objectViaClassExpression.hasOwnProperty("prototypePropertyTwo") && (Object.getPrototypeOf(objectViaClassExpression).ownPropertyOne === undefined) && (typeof ClassExpression.prototype.ownPropertyOne === "undefined") && (typeof ClassExpression.prototype.conciseMethod === "function") && (typeof ClassExpression.prototype.prototypePropertyOne === "string") && (typeof ClassExpression.prototype.prototypePropertyTwo === "function") && objectViaClassExpression.propertyIsEnumerable("ownPropertyOne") && !objectViaClassExpression.propertyIsEnumerable("conciseMethod") && !objectViaClassExpression.propertyIsEnumerable("prototypePropertyOne") && !objectViaClassExpression.propertyIsEnumerable("prototypePropertyTwo")){
 var element = document.getElementById("testId");
 element.innerHTML = "<b>Pass</b> (at least partial/possibly full support): The web browser recognizes the JavaScript <code>class</code> syntax. The web browser at least partially/possibly fully supports the JavaScript <code>class</code> syntax. Positive determination of full web browser support is beyond the scope of this test.";
}
</script>

2.2. Web Browser Support Test Result

Fail (no support): The web browser does not recognize the JavaScript class syntax. The web browser does not support the JavaScript class syntax.


3. Resources And Additional Information