Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8396141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:27:58+00:00 2026-06-09T20:27:58+00:00

define([dojo/_base/declare], function (declare) { // module: // StyleNames // summary: // Style element names.

  • 0
define(["dojo/_base/declare"], function (declare) {
    // module:
    //      StyleNames
    // summary:
    //      Style element names.
    var StyleNames = declare(null, 
        {
            PROP1: "Style1",
            PROP2: "Style2"
        }
    );

    StyleNames.dataContexts = [
        StyleNames.PROP1,
        StyleNames.PROP2,
    ];

    return StyleNames;
});

var styleNames = new StyleNames();
console.log("PROP1 is defined as: ", styleNames.PROP1); // prints "Style1"
console.log("dataContexts is undefined: ", styleNames.dataContexts); // Error: styleNames.dataContexts is undefined

My setup was similar to https://stackoverflow.com/a/11329956/1610451 but looking in the DOM, I can see that it is set to the constructor styleNames.constructor.dataContexts with undefined values.

Backstory: I’m porting ActionScript code to JavaScript and need to maintain existing interfaces. An example of the ActionScript code that I’m porting is:

public class StyleNames {
    public static const PROP1 : String = "Style1";
    public static const PROP2 : String = "Style2";

    public static const dataContexts : Array = [
        PROP1,
        PROP2
    ];

    public function StyleNames(){}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:27:59+00:00Added an answer on June 9, 2026 at 8:27 pm

    You’ve got it right in your declaration. That is the most unambiguous way to define static variables in my opinion. In your console.log code, you’re just not referring to the dataContexts variable correctly. It’s a static variable, so it does not belong to any one instance. You want to refer to it this way: StyleNames.dataContexts.

    Edit: you’ve also got a possible syntax error in there. Take out the second comma under the StyleNames.dataContexts declaration:

    StyleNames.dataContexts = [
        StyleNames.PROP1,
        StyleNames.PROP2
    ];
    

    Access the variable like this:

    StyleNames.dataContexts
    

    as opposed to this.dataContexts or instanceRef.dataContexts

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've created a Dojo module which depends on dojox/data/JsonRestStore like this: define(my/MyRestStore, [dojo/_base/declare, dojox/data/JsonRestStore],
I have the following subclass, derived from ContentPane: define([ dijit/layout/ContentPane, dojo/_base/declare ], function (ContentPane,
file: dojo/dir1/utils/XmlJsonUtils.js // Author: Rajat Khandelwal define([ dojo/_base/declare // declare ], function(declare){ return declare(dir1.utils.XmlJsonUtils,[],{
Is there a way to define a dojo/method programmatically, in a JavaScript function? (Instead
I have a dojo define function like this one define([ // some param ]),function(foo,
dojo.addOnLoad(function(){ var jsonStore = new dojo.data.ItemFileReadStore({url:http://localhost:8080/Sai/samu}); }); <div dojoType=dijit.form.FilteringSelect store=jsonStore required=true id=MyId ></div> I
Ext.define('DigitalPaper.controller.Documents', { extend: 'Ext.app.Controller', views: ['Documents'], stores: ['Documents'], models: ['Documents'], init: function() { console.log('[OK]
Define a function replicate which given a list of numbers returns a list with
(define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car
In an Dojo 1.7 AMD web app you can define also arbitrary data in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.