Note: An alternative skin, TW4MW (work in progress), is available from the user preferences.

Dev:Hijacking

TiddlyWiki Community Wiki

Jump to: navigation, search
This page is still incomplete. You can help by contributing to its expansion.
Please improve the article, or discuss the issue on the talk page.

If possible, hijacking a function is preferable to overriding it, as it is less invasive and thus more future-proof.

[edit] Example

Hijacking global function sampleFunc:

(function() { // closure to create local scope for backup
 
// backup original function
var sampleFunc_orig = sampleFunc;
// override original function
window.sampleFunc = function(foo, bar, baz) { // arguments correspond to original function signature
	// perform custom operations
	/* ... */
	// invoke the original function
	return sampleFunc_orig.apply(this, arguments);
};
 
})();

The wrapping function technique illustrated here is optional, but recommended to avoid clashes with other hijacks.

[edit] External Resources

Personal tools