Javascript
Jump to navigation
Jump to search
Functions
- functions are objects in javascript
- anonymous functions - no name
var foo = function(callback){ callback(); return function() { print" return function called."; }; };
- can add properties to functions, i.e., foo.bar = 'baz';
- javascript does not have classes but
var Foo = function {}; Foo.prototype { 'bar': function() {}; };
- can extend prototypes at any time
- can also extend with a built in type
Number.prototype.celciusToFahrenheit = function(){}; (34).celciusToFahrenheit;
Behaviors
- all functions in Drupal.behaviors are executed onready (when DOM is ready)
- functions get a context parameter to act on
Drupal.behaviors.foo(context)
theming
- ex: slide show, wrap images in markup
var elem - Drupal.theme()
developing javascript widgets
- think about compatibility
- your js wid should not interfere, don't behave as if they're alone on the page.