Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3694896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:33:07+00:00 2026-05-19T04:33:07+00:00

I was just asked to write a little news ticker script for one of

  • 0

I was just asked to write a little news ticker script for one of our websites, so I re-wrote an existing jQuery script to fit our needs. Only afterwards I was told they use Prototype instead of jQuery, so now I have to convert the script.

Most of the simple parts I’ll be able to find out using the Prototype documentation, but there’s some parts in the jQuery that I’m not familiar with. I’m mainly talking about the parts like:

(function($) {

$.fn.newsTicker = $.fn.newsticker = function(delay)
{
    delay = delay || 4000;
    initTicker = function(el)
    {
       //bla bla some stuff
    };

    //here be more functions

    this.each(
        function()
        {
            if(this.nodeName.toLowerCase()!= "ul") return;
            initTicker(this);
        }
    );
};

and

$.newsticker = $.newsTicker =
{
    pause: function(el)
    {
        (el.jquery ? el[0] : el).pause = true;
    },
    //more functions
}

})(jQuery);

Are these some sort of classes? I don’t get how $(#element).newsTicker() fires the right function. How does this work, and more importantly what does it translate to in Prototype?

Full script: http://jsfiddle.net/PXn4r/9/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:33:08+00:00Added an answer on May 19, 2026 at 4:33 am

    I cannot help you with the Prototype port but here’s how the original code works.

    Are these some sort of classes? I
    don’t get how $(#element).newsTicker()
    fires the right function.

    In jQuery you have a single global object, normally aliased as $, that contains all the functions you can use (the “features”). These features are extensible: you can add your own function to the global object and if you do it properly it’ll be undistinguishable from any other jQuery built-in function. If you do it in a reusable style, you’ve written a plug-in. That’s what the code does:

    $.fn.newsTicker = $.fn.newsticker = function(delay){
    }
    

    It creates a jQuery method that accepts a delay parameter. (Actually, it’s defined twice so you can misspell the name.) You can now do stuff like this:

    $("#main div.ticker").newsticker(2000);
    

    Now this:

    (function($) {
        // ...
    })(jQuery);
    

    The $ alias is just a convention and can be available or not. This piece of code defines an unnamed function that receives the jQuery global object and stores it in a local variable called $. That way you can be sure that $ exists and it doesn’t conflict with any other $ variable that may be around.

    Update

    And what’s the difference between the function with .fn and the one without?

    jQuery.fn is a special object for plugins. I don’t know what happens if you add your function anywhere else (it may work as expected or not, I haven’t tested it) but that’s the best practice. You can consider it a namespace: stuff placed there won’t interfere with anything else.

    Reference: http://docs.jquery.com/Plugins/Authoring

    BTW, a properly written plugin allows you to insert it in the middle of a jQuery chain, e.g.:

    $("#main div.ticker").css("color: red").newsticker(2000).fadeIn("slow");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My boss just asked me to write a little test for people that are
i just asked a question few minutes ago which led me to this one
I've just been asked to write an SSRS report that displays data like so:
I just asked a question about whether it was possible to write a web-page-checking
I just asked a question about whether it was possible to write a web-page-checking
I've just been asked to come up with a script to find files with
I've been asked to write code to track IP addresses of visitors to one
I'm asked in my course HW to write a comparison in bash using just
Just asked a question about linking Boost libraries in the make file. Thanks to
Just asked how to check if an internet connection exists using javascript and got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.