Note that there are some explanatory texts on larger screens.

plurals
  1. POExplain this confusing dojo tutorial syntax for declare
    primarykey
    data
    text
    <p>I am reading the syntax for using <a href="http://dojotoolkit.org/documentation/tutorials/1.8/declare/" rel="nofollow">dojo's declare</a> for class creation. The description is confusing:</p> <pre><code>The declare function is defined in the dojo/_base/declare module. declare accepts three arguments: className, superClass, and properties. ClassName The className argument represents the name of the class, including the namespace, to be created. Named classes are placed within the global scope. The className can also represent the inheritance chain via the namespace. Named Class // Create a new class named "mynamespace.MyClass" declare("mynamespace.MyClass", null, { // Custom properties and methods here }); A class named mynamespace.MyClass is now globally available within the application. Named classes should only be created if they will be used with the Dojo parser. All other classes should omit the className parameter. "Anonymous" Class // Create a scoped, anonymous class var MyClass = declare(null, { // Custom properties and methods here }); The MyClass is now only available within its given scope. SuperClass(es) The SuperClass argument can be null, one existing class, or an array of existing classes. If a new class inherits from more than one class, the first class in the list will be the base prototype, the rest will be considered "mixins". Class with No Inheritance var MyClass = declare(null, { // Custom properties and methods here }); null signifies that this class has no classes to inherit from. Class Inheriting from Another Class var MySubClass = declare(MyClass, { // MySubClass now has all of MyClass's properties and methods // These properties and methods override parent's }); </code></pre> <p>The syntax is exactly the same for creating a non-named class and a class with no superclass:</p> <pre><code>var MyClass = declare(null, { // Custom properties and methods here }); </code></pre> <p>I expect the syntax for a class without any super class and without any name to be like this:</p> <pre><code>var MyClass = declare(null, null, { // Custom properties and methods here }); </code></pre> <p>I am coming from a typed language background, so perhaps I've misunderstood how this works in JavaScript. I fail to understand how someone reading the code (without any comments) would know the difference between the two, if the tutorials syntax is correct.</p> <p>I would have expected the syntax to be something like this:</p> <pre><code>/*class without a name:*/ declare(null, SuperClass, {}) /*class without a name or super class:*/ declare(null, null, {}) /*class with a name but no super class:*/ declare("ClassName", null, {}) </code></pre> <p>Maybe this is verbose, but at least it is easy to tell what each parameter is for.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload