Chaplin.utils → Source
Chaplin’s utils provide common functions for use throughout the project.
These functions are generic and not related to any specific Chaplin components. Useful functions for messing with Chaplin are available in Chaplin.helpers.
beget(parent)
- returns a new object with
parent
as its prototype
A standard Javascript helper function that creates an object which delegates to another object. (see Douglas Crockford's Javascript: The Good Parts for more details). Uses Object.create when available, and falls back to a polyfill if not present.
readonly(object, [*properties])
- returns true if successful, false if unsupported by the browser’s runtime
Makes properties of object read-only so they cannot be overwritten. The success of this operation depends on the current environment’s support.
getPrototypeChain(object)
- Object object
Gets the whole chain of prototypes for object
.
getAllPropertyVersions(object, property)
- Object object
- String property
Get all different value versions for property
from object
’s prototype chain. Usage:
class A
prop: 1
class B extends A
prop: 2
b = new B
getAllPropertyVersions b, 'prop' # => [1, 2]
function A() {}
A.prototype.prop = 1;
function B() {}
B.prototype = Object.create(A);
var b = new B;
getAllPropertyVersions(b, 'prop'); // => [1, 2]
upcase(str)
- String
str
- returns upcased version of
str
Ensure the first character of str
is capitalized
utils.upcase 'larry bird' # 'Larry bird'
utils.upcase 'AIR' # 'AIR'
utils.upcase('larry bird'); // 'Larry bird'
utils.upcase('AIR'); // 'AIR'
modifierKeyPressed(event)
- jQuery normalized event object
event
- returns boolean
Looks at an event object event
to determine if the shift, alt, ctrl, or meta keys were pressed. Useful in link click handling (i.e. if you need ctrl-click or shift-click to open the link in a new window).