has

dojo/has

Summary

Return the current value of the named feature.

Returns the value of the feature named by name. The feature must have been previously added to the cache by has.add.

Usage

has(name);
Parameter Type Description
name String | Integer

The name (if a string) or identifier (if an integer) of the feature to test.

Returns: boolean

See the dojo/has reference documentation for more information.

Properties

cache

Defined by: dojo/has

Methods

add(name,test,now,force)

Defined by dojo/has

Register a new feature test for some named feature.

Parameter Type Description
name String | Integer

The name (if a string) or identifier (if an integer) of the feature to test.

test Function

A test function to register. If a function, queued for testing until actually needed. The test function should return a boolean indicating the presence of a feature or bug.

now Boolean
Optional

Optional. Omit if test is not a function. Provides a way to immediately run the test and cache the result.

force Boolean
Optional

Optional. If the test already exists and force is truthy, then the existing test will be replaced; otherwise, add does not replace an existing test (that is, by default, the first test advice wins).

Returns: undefined

Examples

Example 1

A redundant test, testFn with immediate execution:

has.add("javascript", function(){ return true; }, true);

Example 2

Again with the redundantness. You can do this in your tests, but we should not be doing this in any internal has.js tests

has.add("javascript", true);

Example 3

Three things are passed to the testFunction. global, document, and a generic element from which to work your test should the need arise.

has.add("bug-byid", function(g, d, el){
    // g    == global, typically window, yadda yadda
    // d    == document object
    // el == the generic element. a `has` element.
    return false; // fake test, byid-when-form-has-name-matching-an-id is slightly longer
});

clearElement(element)

Defined by dojo/has

Deletes the contents of the element passed to test functions.

Parameter Type Description
element undefined

load(id,parentRequire,loaded)

Defined by dojo/has

Conditional loading of AMD modules based on a has feature test value.

Parameter Type Description
id String

Gives the resolved module id to load.

parentRequire Function

The loader require function with respect to the module that contained the plugin resource in it's dependency list.

loaded Function

Callback to loader that consumes result of plugin demand.

normalize(id,toAbsMid)

Defined by dojo/has

Resolves id into a module id based on possibly-nested tenary expression that branches on has feature test value(s).

Parameter Type Description
id undefined
toAbsMid Function

Resolves a relative module id into an absolute module id

© 2005–2015 The Dojo Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/has.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部