Provides core language utilites and extensions used throughout YUI.
true if the given function appears to be implemented in native code,
false otherwise. Will always return
false -- even in ES5-capable browsers --
useNativeES5 YUI config option is set to
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.
Function to test.
trueif fn appears to be native,
Determines whether or not the provided item is an array.
false for array-like collections such as the function
HTMLElement collections. Use
Y.Array.test() if you want to
test for an array-like collection.
Determines whether or not the provided item is a boolean.
Determines whether or not the supplied item is a date instance.
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.
Determines whether or not the provided item is null.
Determines whether or not the provided item is a legal number.
Determines whether or not the provided item is of type object
or function. Note that arrays are also objects, so
Y.Lang.isObject() === true.
Determines whether or not the provided item is a string.
Determines whether or not the provided item is undefined.
A convenience method for detecting a legitimate non-null value. Returns false for null/undefined/NaN, true for other values, including 0/false/''
The item to test.
Returns the current time in milliseconds.
Lightweight version of
Y.substitute. Uses the same template
Y.substitute, but doesn't support recursion,
auto-object coersion, or formats.
Returns a string without any leading or trailing whitespace. If the input is not a string, the input will be returned untouched.
Returns a string without any leading whitespace.
Returns a string without any trailing whitespace.
Returns one of the following strings, representing the type of the item passed in:
typeof HTMLElementCollectionreturns function in Safari, but
Y.Lang.type()reports "object", which could be a good thing -- but it actually caused the logic in
the item to test.