Dojo Learning Notes 3. Dojo's underlying objects and methods

Source: Internet
Author: User
Tags anonymous require

The underlying objects and methods described here refer to objects and methods that are capable of being invoked without require any packets.

anonymous functions

Before I start, I'd like to introduce the anonymous function in JS, which is when I read the source code of dojo, I find that there are anonymous functions everywhere.

;(function(){
alert(123);
})();

The preceding semicolon is an empty statement and is not possible.

anonymous function. An anonymous function is a function that has no name.

You can think of them as a one-time function. They are especially useful when you need to use only one function at a time. By using anonymous functions, it is not necessary to keep functions in memory, so using anonymous functions is more efficient.

Of course you can not define functions at all, but using anonymous functions can fragment your code, just like the #region in C #

Dojo.byid

A very useful method, as with Prototype.js's famous $

It seems that the previous version has Dojo.byidarray, but the latest version has not found this function (except Src\compat\0.2.2.js)

If more than one element has the specified ID, a collection is returned

Usage Example:

dojo.byId("divTest");
dojo.byId("divTest", document);
dojo.byId(document.getElementById("divTest"));

Dojo.version

The dojo version can be obtained major, minor, patch, flag and revision

This object is of little use unless you choose to execute your code according to the dojo version.

Dojo.raise

Throws an exception

Dojo.errortostring

Convert an exception to a string

Usage Example:
try
{
  dojo.raise("打印失败", new Error("文件不存在"));
}
catch(e)
{
  alert(dojo.errorToString(e));
}

Dojo.render

System Environment Objects

dojo.render.name   返回 browser ,说明是工作在浏览器下
dojo.render.ver    返回 4 ,似乎没什么用
dojo.os.win      返回true说明操作系统是Windows
dojo.os.linux      返回true说明操作系统是Linux
dojo.os.osx      返回true说明操作系统是MacOS
dojo.html.ie       返回true说明浏览器是Internet Explorer
dojo.html.opera       返回true说明浏览器是Opera
dojo.html.khtml       返回true说明浏览器是Konqueror
dojo.html.safari   返回true说明浏览器是Safari
dojo.html.moz    返回true说明浏览器是Mozilla FireFox
dojo.svg.capable   返回true说明浏览器支持svg
dojo.vml.capable   返回true说明浏览器支持vml
dojo.swf.capable  返回true说明浏览器支持swf
dojo.swt.capable   返回true说明浏览器支持swt (IBM开发的Standard Widget Toolkit)

If dojo.html.ie is True

dojo.html.ie50     返回true说明浏览器是IE 5.0
dojo.html.ie55     返回true说明浏览器是IE 5.5
dojo.html.ie60     返回true说明浏览器是IE 6.0
dojo.html.ie70     返回true说明浏览器是IE 7.0

Dojo.addonload

Can be loaded when the specified function is executed to window.load, the advantage is that it is convenient to perform multiple functions while Window.load

Usage Example:

dojo.addOnLoad(init);          //init是一个函数
dojo.addOnLoad(myObject, init);    //init是myObject对象的一个方法

Dojo.require

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.