Provides core language utilites and extensions used throughout YUI.
_isNativefn
Defined in
yui/js/yui-lang.js:45
Available since 3.5.0
Returns true if the given function appears to be implemented in native code,
false otherwise. Will always return false -- even in ES5-capable browsers --
if the useNativeES5 YUI config option is set to false.
This isn't guaranteed to be 100% accurate and won't work for anything other than
functions, but it can be useful for determining whether a function like
Array.prototype.forEach is native or a JS shim provided by another library.
There's a great article by @kangax discussing certain flaws with this technique: http://perfectionkills.com/detecting-built-in-host-methods/
While his points are valid, it's still possible to benefit from this function as long as it's used carefully and sparingly, and in such a way that false negatives have minimal consequences. It's used internally to avoid using potentially broken non-native ES5 shims that have been added to the page by other libraries.
fn
Function
Function to test.
true if fn appears to be native, false otherwise.
isArrayo
Defined in
yui/js/yui-lang.js:76
Determines whether or not the provided item is an array.
Returns false for array-like collections such as the function arguments
collection or HTMLElement collections. Use Y.Array.test() if you want to
test for an array-like collection.
o
Object
The object to test.
true if o is an array.
isBooleano
Defined in
yui/js/yui-lang.js:92
Determines whether or not the provided item is a boolean.
o
Object
The object to test.
true if o is a boolean.
isDateo
Defined in
yui/js/yui-lang.js:103
Determines whether or not the supplied item is a date instance.
o
Object
The object to test.
true if o is a date.
isFunctiono
Defined in
yui/js/yui-lang.js:114
Determines whether or not the provided item is a function. Note: Internet Explorer thinks certain functions are objects:
var obj = document.createElement("object");
Y.Lang.isFunction(obj.getAttribute) // reports false in IE
var input = document.createElement("input"); // append to body
Y.Lang.isFunction(input.focus) // reports false in IE
You will have to implement additional tests if these functions matter to you.
o
Object
The object to test.
true if o is a function.
isNullo
Defined in
yui/js/yui-lang.js:142
Determines whether or not the provided item is null.
o
Object
The object to test.
true if o is null.
isNumbero
Defined in
yui/js/yui-lang.js:153
Determines whether or not the provided item is a legal number.
o
Object
The object to test.
true if o is a number.
isObjecto
failfn
Defined in
yui/js/yui-lang.js:164
Determines whether or not the provided item is of type object
or function. Note that arrays are also objects, so
Y.Lang.isObject([]) === true.
true if o is an object.
isRegExpvalue
Defined in
yui/js/yui-lang.js:181
Determines whether or not the provided value is a regexp.
value
Object
The value or object to test.
true if value is a regexp.
isStringo
Defined in
yui/js/yui-lang.js:192
Determines whether or not the provided item is a string.
o
Object
The object to test.
true if o is a string.
isUndefinedo
Defined in
yui/js/yui-lang.js:203
Determines whether or not the provided item is undefined.
o
Object
The object to test.
true if o is undefined.
isValueo
Defined in
yui/js/yui-lang.js:214
A convenience method for detecting a legitimate non-null value. Returns false for null/undefined/NaN, true for other values, including 0/false/''
o
Object
The item to test.
true if it is not null/undefined/NaN || false.
now
Defined in
yui/js/yui-lang.js:239
Available since 3.3.0
Returns the current time in milliseconds.
Current time in milliseconds.
subs
o
Defined in
yui/js/yui-lang.js:251
Available since 3.2.0
Performs {placeholder} substitution on a string. The object passed as the
second parameter provides values to replace the {placeholder}s.
{placeholder} token names must match property names of the object. For example,
var greeting = Y.Lang.sub("Hello, {who}!", { who: "World" });
{placeholder} tokens that are undefined on the object map will be left
in tact (leaving unsightly {placeholder}'s in the output string).
the substitute result.
trims
Defined in
yui/js/yui-lang.js:274
Returns a string without any leading or trailing whitespace. If the input is not a string, the input will be returned untouched.
s
String
the string to trim.
the trimmed string.
trimLefts
Defined in
yui/js/yui-lang.js:292
Returns a string without any leading whitespace.
s
String
the string to trim.
the trimmed string.
trimRights
Defined in
yui/js/yui-lang.js:305
Returns a string without any trailing whitespace.
s
String
the string to trim.
the trimmed string.
typeo
Defined in
yui/js/yui-lang.js:318
Returns one of the following strings, representing the type of the item passed in:
Known issues:
typeof HTMLElementCollection returns function in Safari, but
Y.Lang.type() reports "object", which could be a good thing --
but it actually caused the logic in Y.Lang.isObject to fail.o
Object
the item to test.
the detected type.