UNPKG

qcobjects-docs

Version:

The official app and website for documentation of QCObjects

39 lines (30 loc) 1.25 kB
### Class This is NOT the class definition of ECMAScript 2015 (see [class ECMAScript 2015](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes) for reference). Class is a special function to help you to declare a class in an easier and compatible way. It works cross-browser, and I hope ECMA could adopt something like that in the future. To let javascript not to be confuse about this, [QCObjects](https://qcobjects.dev) uses "Class" not "class" (note the Camel Case). #### Usage: ```javascript Class('MyClassName',MyClassDefinition); ``` Where **MyClassDefinition** is an object with a QCObjects **prototype** #### Example: ```javascript Class('MyClassName',InheritClass,{ propertyName1:0, // just to declare purpose propertyName2:'', classMethod1: function (){ // some code here // note you can use "this" object return this.propertyName1; }, classMethod2: function () { // some code here return this.propertyName2; } }); var newObject = New(MyClassName,{ propertyName1:1, // this initializes the value in 1 propertyName2:"some value" }); console.log(newObject.classMethod1()); // this will show number 1 console.log(newObject.classMethod2()); // this will show "some value" ```