Is attaching functions to the jQuery object bad practice?

Currently I have a jQuery plugin which not only sets up its function in $.fn but also $ itself, checking if (typeof(this) == ‘function’) to see if it has been called through $.pluginname or $(elm).pluginname… is this bad practice, and if so, is there a better way to make providing the element optional?

Javascript – Storing function in object – bad practice?

Is it considered bad coding-practice to store functions in an object instead of just defining them (and therefore globally)? Consider: 1. Foo = { bar: function() { alert(baz); } }; vs. 2.

Bad practice to use Variable functions?

Ok, really simple question – is it bad practice to use Variable functions in php? I have a validator class that can use these and it makes sense to me but it does seem like it may be bad practice to d

Are anonymous functions a bad practice in JavaScript?

I was reading that using anonymous functions in javascript is bad practice, because it can make debugging a pain, but I haven’t seen this for myself. Are anonymous functions in JavaScript really bad p

Is supplying alike default special member functions a bad practice?

We just have a discussion over here about explicitly declaring the special member functions. Is it bad practice doing so? What I mean: The compiler generated versions perform memberwise operations. If

Attaching underscore to Object prototype, bad idea?

The common wisdom is the just because you can augment native types, doesn’t mean you should. That augmenting a native types prototype is a bad idea always, with the only exception being to polyfill be

Static method get – is this bad practice?

Had a discussion with a colleague about wether this is bad practice or not. Now I can not find immediate examples of this online. We have a lot of database object mappers and call it’s functions like

Is it bad practice to instantiate an object as an argument inside a method/function call?

Is it bad practice to instantiate an object as an argument? For example, is it bad practice to do this? myFunction(new Foo); Or should you always do it this way: $foo = new Foo; myFunction($foo); My

is it bad practice to parameters through a string of functions?

im building a reasonably large JS application and i wanted to get your opinions on some of the logic. i wanted to know if its considered bad practice to pass a parameter through a string of functions

Why is it considered bad practice to use “global” reference inside functions? [duplicate]

Possible Duplicate: Are global variables in PHP considered bad practice? If so, why? global in functions Project summary – I am writing a web CMS to get my feet wet with PHP / MySQL. In order to bre

Is it bad practice to echo out functions in php?

Is it bad practice to echo out a bunch of HTML using a function in php and having it something like this: function my_function() { global $post; $custom_fields = get_post_custom(); $some_field = $cust


The jquery extend function is exposed on both namespaces:

The jQuery source defines both as:

$.extend = $.fn.extend = ...

This would lead me to believe that they intended for you to be able to do this. However, if you look at the way the jQuery authors have set up their own functions to use both, you may get a better idea of the best practice.

For instance, you would normally want the $.fn function to call the $ function. (Much like the $.data function in the jQuery source)

  data: function(elem, key, value) {...}

and (a bit simplified):

  data: function(key, value){
    return this.each(function(){
      $.data(this, key, value);

This way, one calls the other and takes care of the check for which version you are using, and if you wanted to, you could just check for an undefined ‘elem’ param in the $ namespace.

Have you had a read through the jquery authoring docs? The log function in the example is considered the standard way of adding functions to the jquery object for developers.