convert this namespace into jQuery

Posted on 2013-12-01
Last Modified: 2013-12-03
I have the following code but how would you convert it into a jQuery namespace

    multiply: function(x,y) {
        return (x * y);
//function call

Open in new window

Question by:stargateatlantis
LVL 35

Expert Comment

by:Miguel Oz
ID: 39688678
Use the jQuery.fn.extend method:
    multiply: function(x,y) {
        return (x * y);

Open in new window

or you can declare your new method as:
$.fn.multiply= function(){
  return (x * y);

Open in new window

Note: The first alternative is more flexible and reusable as discussed below:
LVL 44

Accepted Solution

Rainer Jeschor earned 500 total points
ID: 39688690

could look like this:
var JQUERY4U = {}; 
;(function($) {

     JQUERY4U.EESample= {
         multiply: function(x,y) {
        return (x * y);

Open in new window

(adjusted from

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery ( 1.6 introduces .prop() ( and .removeProp() ( methods which allow modifying or removi…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question