Documentation
dojo/_base/kernel¶
Contents
dojo/_base/kernel is a module that contains some of the very basic features that are part of Dojo. The module us not usually required directly by end developers, unless required for creating additional modules that are part of the toolkit.
Usage¶
As with the rest of dojo/_base modules, if you are running the Dojo loader in legacy mode (async: false) this module is automatically loaded, also most core modules directly or indirectly depend on this module. Even if it is automatically loaded, you should require it in to have access to its features:
define(["dojo/_base/kernel"], function(kernel){
// kernal has the module's features
});
Features¶
deprecated()¶
This function logs a warning message to the console, alerting developers a method or package has been removed, replaced, or otherwise has been changed, and they are using an “older” version of the method. isDebug needs to be set to true for these messages to appear.
require(["dojo/_base/kernel"], function(kernel){
kernel.deprecated("dijit.layout.SplitContainer", "Use dijit.layout.BorderContainer instead", "2.0");
});
This means the “SplitContainer” widget still works, but has been replaced by the BorderContainer widget, and will be removed in Dojo 2.0.
The signature of the method is:
Name | Type | Description |
---|---|---|
behaviour | String | The API or behavior being deprecated. Usually in the form of "myApp.someFunction()". |
extra | String | Text to append to the message. Often provides advice on a new function or facility to achieve the same goal during the deprecation period. |
removal | String | Text to indicate when in the future the behavior will be removed. Usually a version number. |
experimental()¶
This function logs a warning message to the console, alerting developers a method or module is experimental. isDebug needs to be set to true for these messages to appear.
require(["dojo/_base/kernel"], function(kernel){
kernel.experimental("acme.MyClass");
});
The signature of the method is:
Name | Type | Description |
---|---|---|
moduleName | String | The name of a module, or the name of a module file or a specific function |
extra | String | some additional message for the user |
global¶
global is an alias for the global scope.
In a browser environment, global is the window object. You should refer to global rather than window so that your code will run correctly in other contexts (e.g. Rhino or NodeJS).
// connect a global "onclick" handler
require(["dojo/_base/kernel", "dojo/on"], function(kernel, on){
on(kernel.global, "click", function(e){
console.log("clicked: ", e.target);
});
});
Though this example is clearly targeted at a browser environment, by using global over the window object we are ensuring the code will run in any other environments with a defined host environment file.
See also dojo/_base/window::withGlobal.
locale¶
locale contains the locale for loading localized resources, specified according to RFC 3066. This string can be specified with the help of dojo/_base/config::locale <dojo/_base/config#locale.
A simple reference of locale:
require(["dojo/_base/kernel"], function(kernel){
var currentLocale = kernel.locale;
});
version¶
An object describing the current version of dojo.js:
>>> require(["dojo/_base/kernel"], function(kernel){ console.log(kernel.version); });
0.0.0dev (15278) major=0 minor=0 patch=0 flag=dev revision=15278
0.0.0 indicates a "trunk" release, a non-built version of Dojo. Typically you will see a real version, such as 1.8.0.
The members of the version object are integers, and can be checked individually:
require(["dojo/_base/kernel"], function(kernel){
var v = kernel.version;
if(v.major > 1){
// this is Dojo 2.x or greater
}else{
// this id Dojo 1.x
switch(v.minor){
case 1: console.log("1.1.x specific code"); break;
case 2: console.log("1.2.x specific code"); break;
case 9: console.log("this is 0.9, as major is less than 1, but not 1"); break;
}
}
});
It is important to note the version value is easily set as part of the build process (version=1.8.0), and should not be relied upon in production code. It is meant as a simple utility for determining which particular version of Dojo is loaded on a page, mostly for debugging purposes.
The revision member refers to the SVN revision used to create the version. You can inspect individual changesets at the Dojo ticket tracker.
require(["dojo/_base/kernel", "dojo/query", "dojo/NodeList-dom", "dojo/domReady!"], function(kernel, query){
query(".info").attr("innerHTML", kernel.version);
});
<div class="info"></div>
See Also¶
- dojo/_base - The "base" of Dojo.
- dojo - The "core" of Dojo.