jQuery: The Write Less, Do More JavaScript Library

Question on : syntax

View: New views
8 Messages — Rating Filter:   Alert me  

Question on : syntax

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I have yet another syntax question.

I know that : can be used for specifying things like filters, but what
does it do in this case:

    $jc.fn.extend({

        setup: function() {
            this.first     = null;
            this.last      = null;
            this.prevFirst = null;
            this.prevLast  = null;
            this.animating = false;
            this.timer     = null;
            this.tail      = null;
            this.inTail    = false;

            if (this.locked)
                return;

            this.list.css(this.lt, this.pos(this.options.offset) +
'px');
            ...rest of code here
        },

so what is the syntax setup:    an attribute?

Re: Question on : syntax

by Michael Lawson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One thing to keep in mind, is that when you are using : to specify a filter, it will always be inside of a string. "input:button" for example.
The syntax you have here is the key value notation in javascript. It will almost always exist outside of a string. You are setting the setup key to the anonymous function you have there.

cheers

Michael Lawson
Development Lead, Global Solutions, ibm.com
Phone: 1-276-206-8393
E-mail: mjlawson@...

'Examine my teachings critically, as a gold assayer would test gold. If you find they make sense, conform to your experience, and don't harm yourself or others, only then should you accept them.'

Inactive hide details for expresso ---07/02/2009 01:09:31 PM---I have yet another syntax question.expresso ---07/02/2009 01:09:31 PM---I have yet another syntax question.


From:

expresso <dschinkel@...>

To:

"jQuery (English)" <jquery-en@...>

Date:

07/02/2009 01:09 PM

Subject:

[jQuery] Question on : syntax






I have yet another syntax question.

I know that : can be used for specifying things like filters, but what
does it do in this case:

   $jc.fn.extend({

       setup: function() {
           this.first     = null;
           this.last      = null;
           this.prevFirst = null;
           this.prevLast  = null;
           this.animating = false;
           this.timer     = null;
           this.tail      = null;
           this.inTail    = false;

           if (this.locked)
               return;

           this.list.css(this.lt, this.pos(this.options.offset) +
'px');
           ...rest of code here
       },

so what is the syntax setup:    an attribute?





Re: Question on : syntax

by waseem sabjee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

lets go back to basic JavaScript.
take this example

var display = function() { // create namespace display

return {

hide : function(o) { // add function hide to namepsace
var obj = document.getElementById(o);
if(obj.style.display != 'none') {
obj.style.display = 'none'
}
},

show : function(o) { // add function show to namespace
var obj = document.getElementById(o);
if(obj.style.display = 'none') {
obj.style.display = 'block'
}
}

};

}();

function init() {
display.hide("mydiv");
setTimeout("display.show('mydiv'), 1000);
}
window.onload = init;


it is a more object orientated way of scripting

as you can see i created my own namespace called display
then i assigned two function to it
display.hide
and
display.show

so you can say your are creating your own namespae with it's own set of functions.
the cool thing is if i create a namespace that controls sideshow behavior i can reuse my display namespace for the hide show transitions.


On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschinkel@...> wrote:

I have yet another syntax question.

I know that : can be used for specifying things like filters, but what
does it do in this case:

   $jc.fn.extend({

       setup: function() {
           this.first     = null;
           this.last      = null;
           this.prevFirst = null;
           this.prevLast  = null;
           this.animating = false;
           this.timer     = null;
           this.tail      = null;
           this.inTail    = false;

           if (this.locked)
               return;

           this.list.css(this.lt, this.pos(this.options.offset) +
'px');
           ...rest of code here
       },

so what is the syntax setup:    an attribute?


Re: Question on : syntax

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks a lot.  The second response really helped me as I'm not so
versed in hard core JavaScript.  Obviously not being that well versed
in it is hindering my ability to understand plug-in code, ability to
distinguish between standard JavaScript notation/features vs. jQuery
in the same file, and ability to understand jQuery a bit also.

migrane every day until I get this stuff down, not as simply as
everyone says.  Yea jQuery is simple once you are a master at
JavaScript and master of the jQuery language!  I love that claim.

On Jul 2, 1:00 pm, waseem sabjee <waseemsab...@...> wrote:

> lets go back to basic JavaScript.
> take this example
>
> var display = function() { // create namespace display
>
> return {
>
> hide : function(o) { // add function hide to namepsace
> var obj = document.getElementById(o);
> if(obj.style.display != 'none') {
> obj.style.display = 'none'
>
> }
> },
>
> show : function(o) { // add function show to namespace
> var obj = document.getElementById(o);
> if(obj.style.display = 'none') {
> obj.style.display = 'block'
>
> }
> }
> };
> }();
>
> function init() {
> display.hide("mydiv");
> setTimeout("display.show('mydiv'), 1000);}
>
> window.onload = init;
>
> it is a more object orientated way of scripting
>
> as you can see i created my own namespace called display
> then i assigned two function to it
> display.hide
> and
> display.show
>
> so you can say your are creating your own namespae with it's own set of
> functions.
> the cool thing is if i create a namespace that controls sideshow behavior i
> can reuse my display namespace for the hide show transitions.
>
> On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschin...@...> wrote:
>
> > I have yet another syntax question.
>
> > I know that : can be used for specifying things like filters, but what
> > does it do in this case:
>
> >    $jc.fn.extend({
>
> >        setup: function() {
> >            this.first     = null;
> >            this.last      = null;
> >            this.prevFirst = null;
> >            this.prevLast  = null;
> >            this.animating = false;
> >            this.timer     = null;
> >            this.tail      = null;
> >            this.inTail    = false;
>
> >            if (this.locked)
> >                return;
>
> >            this.list.css(this.lt, this.pos(this.options.offset) +
> > 'px');
> >            ...rest of code here
> >        },
>
> > so what is the syntax setup:    an attribute?

Re: Question on : syntax

by CoffeeAddict :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


what is meant by a namespace.  I view namespace as like in .NET
classes, is this the same concept?

On Jul 2, 1:10 pm, expresso <dschin...@...> wrote:

> Thanks a lot.  The second response really helped me as I'm not so
> versed in hard core JavaScript.  Obviously not being that well versed
> in it is hindering my ability to understand plug-in code, ability to
> distinguish between standard JavaScript notation/features vs. jQuery
> in the same file, and ability to understand jQuery a bit also.
>
> migrane every day until I get this stuff down, not as simply as
> everyone says.  Yea jQuery is simple once you are a master at
> JavaScript and master of the jQuery language!  I love that claim.
>
> On Jul 2, 1:00 pm, waseem sabjee <waseemsab...@...> wrote:
>
> > lets go back to basic JavaScript.
> > take this example
>
> > var display = function() { // create namespace display
>
> > return {
>
> > hide : function(o) { // add function hide to namepsace
> > var obj = document.getElementById(o);
> > if(obj.style.display != 'none') {
> > obj.style.display = 'none'
>
> > }
> > },
>
> > show : function(o) { // add function show to namespace
> > var obj = document.getElementById(o);
> > if(obj.style.display = 'none') {
> > obj.style.display = 'block'
>
> > }
> > }
> > };
> > }();
>
> > function init() {
> > display.hide("mydiv");
> > setTimeout("display.show('mydiv'), 1000);}
>
> > window.onload = init;
>
> > it is a more object orientated way of scripting
>
> > as you can see i created my own namespace called display
> > then i assigned two function to it
> > display.hide
> > and
> > display.show
>
> > so you can say your are creating your own namespae with it's own set of
> > functions.
> > the cool thing is if i create a namespace that controls sideshow behavior i
> > can reuse my display namespace for the hide show transitions.
>
> > On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschin...@...> wrote:
>
> > > I have yet another syntax question.
>
> > > I know that : can be used for specifying things like filters, but what
> > > does it do in this case:
>
> > >    $jc.fn.extend({
>
> > >        setup: function() {
> > >            this.first     = null;
> > >            this.last      = null;
> > >            this.prevFirst = null;
> > >            this.prevLast  = null;
> > >            this.animating = false;
> > >            this.timer     = null;
> > >            this.tail      = null;
> > >            this.inTail    = false;
>
> > >            if (this.locked)
> > >                return;
>
> > >            this.list.css(this.lt, this.pos(this.options.offset) +
> > > 'px');
> > >            ...rest of code here
> > >        },
>
> > > so what is the syntax setup:    an attribute?

Re: Question on : syntax

by waseem sabjee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

i will use simple terms

when i say namespace
lets call our namespace bmw
this should be a little simpler.
someone decides to create bmw as namespace or brand name
now one of the functions or perks of this is that you can paint it a certain color.

you could say it's like create your own brand name and adding functions and perks to it that will attract people to use your brand.

var bmw = function() {
 return {
paint: function(color, o);
var obj = document.getElementById(o);
o.style.color = color;
}
};
}();

On Thu, Jul 2, 2009 at 8:10 PM, expresso <dschinkel@...> wrote:

Thanks a lot.  The second response really helped me as I'm not so
versed in hard core JavaScript.  Obviously not being that well versed
in it is hindering my ability to understand plug-in code, ability to
distinguish between standard JavaScript notation/features vs. jQuery
in the same file, and ability to understand jQuery a bit also.

migrane every day until I get this stuff down, not as simply as
everyone says.  Yea jQuery is simple once you are a master at
JavaScript and master of the jQuery language!  I love that claim.

On Jul 2, 1:00 pm, waseem sabjee <waseemsab...@...> wrote:
> lets go back to basic JavaScript.
> take this example
>
> var display = function() { // create namespace display
>
> return {
>
> hide : function(o) { // add function hide to namepsace
> var obj = document.getElementById(o);
> if(obj.style.display != 'none') {
> obj.style.display = 'none'
>
> }
> },
>
> show : function(o) { // add function show to namespace
> var obj = document.getElementById(o);
> if(obj.style.display = 'none') {
> obj.style.display = 'block'
>
> }
> }
> };
> }();
>
> function init() {
> display.hide("mydiv");
> setTimeout("display.show('mydiv'), 1000);}
>
> window.onload = init;
>
> it is a more object orientated way of scripting
>
> as you can see i created my own namespace called display
> then i assigned two function to it
> display.hide
> and
> display.show
>
> so you can say your are creating your own namespae with it's own set of
> functions.
> the cool thing is if i create a namespace that controls sideshow behavior i
> can reuse my display namespace for the hide show transitions.
>
> On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschin...@...> wrote:
>
> > I have yet another syntax question.
>
> > I know that : can be used for specifying things like filters, but what
> > does it do in this case:
>
> >    $jc.fn.extend({
>
> >        setup: function() {
> >            this.first     = null;
> >            this.last      = null;
> >            this.prevFirst = null;
> >            this.prevLast  = null;
> >            this.animating = false;
> >            this.timer     = null;
> >            this.tail      = null;
> >            this.inTail    = false;
>
> >            if (this.locked)
> >                return;
>
> >            this.list.css(this.lt, this.pos(this.options.offset) +
> > 'px');
> >            ...rest of code here
> >        },
>
> > so what is the syntax setup:    an attribute?


Re: Question on : syntax

by waseem sabjee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

it is similar do dotnet yes

JS
==========
var mynamespace = function() {
 return {
hide : function(o) {
var obj = document.getElementById(o);
o.style.display = 'none'
}
}
}();


dot net C#
==========

namespace mynamespace {

void hideElemen(string elementName)t {
elementName.visibility = false;
}
}




On Thu, Jul 2, 2009 at 8:15 PM, expresso <dschinkel@...> wrote:

what is meant by a namespace.  I view namespace as like in .NET
classes, is this the same concept?

On Jul 2, 1:10 pm, expresso <dschin...@...> wrote:
> Thanks a lot.  The second response really helped me as I'm not so
> versed in hard core JavaScript.  Obviously not being that well versed
> in it is hindering my ability to understand plug-in code, ability to
> distinguish between standard JavaScript notation/features vs. jQuery
> in the same file, and ability to understand jQuery a bit also.
>
> migrane every day until I get this stuff down, not as simply as
> everyone says.  Yea jQuery is simple once you are a master at
> JavaScript and master of the jQuery language!  I love that claim.
>
> On Jul 2, 1:00 pm, waseem sabjee <waseemsab...@...> wrote:
>
> > lets go back to basic JavaScript.
> > take this example
>
> > var display = function() { // create namespace display
>
> > return {
>
> > hide : function(o) { // add function hide to namepsace
> > var obj = document.getElementById(o);
> > if(obj.style.display != 'none') {
> > obj.style.display = 'none'
>
> > }
> > },
>
> > show : function(o) { // add function show to namespace
> > var obj = document.getElementById(o);
> > if(obj.style.display = 'none') {
> > obj.style.display = 'block'
>
> > }
> > }
> > };
> > }();
>
> > function init() {
> > display.hide("mydiv");
> > setTimeout("display.show('mydiv'), 1000);}
>
> > window.onload = init;
>
> > it is a more object orientated way of scripting
>
> > as you can see i created my own namespace called display
> > then i assigned two function to it
> > display.hide
> > and
> > display.show
>
> > so you can say your are creating your own namespae with it's own set of
> > functions.
> > the cool thing is if i create a namespace that controls sideshow behavior i
> > can reuse my display namespace for the hide show transitions.
>
> > On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschin...@...> wrote:
>
> > > I have yet another syntax question.
>
> > > I know that : can be used for specifying things like filters, but what
> > > does it do in this case:
>
> > >    $jc.fn.extend({
>
> > >        setup: function() {
> > >            this.first     = null;
> > >            this.last      = null;
> > >            this.prevFirst = null;
> > >            this.prevLast  = null;
> > >            this.animating = false;
> > >            this.timer     = null;
> > >            this.tail      = null;
> > >            this.inTail    = false;
>
> > >            if (this.locked)
> > >                return;
>
> > >            this.list.css(this.lt, this.pos(this.options.offset) +
> > > 'px');
> > >            ...rest of code here
> > >        },
>
> > > so what is the syntax setup:    an attribute?


Re: Question on : syntax

by waseem sabjee :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

correction to my dotnet cod

namespace mynamespace {

public class myclass{

void hideElemen(string elementName)t {
elementName.visibility = false;
}
}

}
}

On Thu, Jul 2, 2009 at 8:21 PM, waseem sabjee <waseemsabjee@...> wrote:
it is similar do dotnet yes

JS
==========
var mynamespace = function() {
 return {
hide : function(o) {

var obj = document.getElementById(o);
o.style.display = 'none'
}
}
}();


dot net C#
==========

namespace mynamespace {

void hideElemen(string elementName)t {
elementName.visibility = false;

}
}




On Thu, Jul 2, 2009 at 8:15 PM, expresso <dschinkel@...> wrote:

what is meant by a namespace.  I view namespace as like in .NET
classes, is this the same concept?

On Jul 2, 1:10 pm, expresso <dschin...@...> wrote:
> Thanks a lot.  The second response really helped me as I'm not so
> versed in hard core JavaScript.  Obviously not being that well versed
> in it is hindering my ability to understand plug-in code, ability to
> distinguish between standard JavaScript notation/features vs. jQuery
> in the same file, and ability to understand jQuery a bit also.
>
> migrane every day until I get this stuff down, not as simply as
> everyone says.  Yea jQuery is simple once you are a master at
> JavaScript and master of the jQuery language!  I love that claim.
>
> On Jul 2, 1:00 pm, waseem sabjee <waseemsab...@...> wrote:
>
> > lets go back to basic JavaScript.
> > take this example
>
> > var display = function() { // create namespace display
>
> > return {
>
> > hide : function(o) { // add function hide to namepsace
> > var obj = document.getElementById(o);
> > if(obj.style.display != 'none') {
> > obj.style.display = 'none'
>
> > }
> > },
>
> > show : function(o) { // add function show to namespace
> > var obj = document.getElementById(o);
> > if(obj.style.display = 'none') {
> > obj.style.display = 'block'
>
> > }
> > }
> > };
> > }();
>
> > function init() {
> > display.hide("mydiv");
> > setTimeout("display.show('mydiv'), 1000);}
>
> > window.onload = init;
>
> > it is a more object orientated way of scripting
>
> > as you can see i created my own namespace called display
> > then i assigned two function to it
> > display.hide
> > and
> > display.show
>
> > so you can say your are creating your own namespae with it's own set of
> > functions.
> > the cool thing is if i create a namespace that controls sideshow behavior i
> > can reuse my display namespace for the hide show transitions.
>
> > On Thu, Jul 2, 2009 at 7:08 PM, expresso <dschin...@...> wrote:
>
> > > I have yet another syntax question.
>
> > > I know that : can be used for specifying things like filters, but what
> > > does it do in this case:
>
> > >    $jc.fn.extend({
>
> > >        setup: function() {
> > >            this.first     = null;
> > >            this.last      = null;
> > >            this.prevFirst = null;
> > >            this.prevLast  = null;
> > >            this.animating = false;
> > >            this.timer     = null;
> > >            this.tail      = null;
> > >            this.inTail    = false;
>
> > >            if (this.locked)
> > >                return;
>
> > >            this.list.css(this.lt, this.pos(this.options.offset) +
> > > 'px');
> > >            ...rest of code here
> > >        },
>
> > > so what is the syntax setup:    an attribute?