The meaning of the colon (:), maybe ... what? Similarly equal to (=)?

An exception is ":this()"also inside operators "if()", what can an operator mean ":"?

In the following example, which seems to be irrelevant, I want to find <a href>one of two things in the link collection :

  • all elements that do not have a class .ib-content;
  • the first <span>inside all found links <a href>that match the criteria having "objToWhom_Id" (func passed var) on, this is the text.

So, for example, in this code:

init_stuff = function(objToWhom_Id) { 
   $ibItems        = $ibWrapper.find('div.ib-main > a');
   $ibImgItems     = $ibItems.not('.ib-content');

   if(objToWhom_Id == "allHTMLitems"){
       imgItemsCount = $ibImgItems.length;
   }else{
       ++imgItemsCount;
       //Here we are; notice the ":"
       $ibImgItems : $ibItems.find('span:first').filter(':contains(objToWhom_Id)');
       //
       console.log($ibImgItems.html();
   }
}

everything works fine (the init_stuff () function is delayed, btw) ...

But if we change the above line to:

       $ibImgItems = $ibItems.find('span:first').filter(':contains(objToWhom_Id)');

which should be reasonable doesn't work anymore ... :-P

Any help?


EDITED

":" , ( !) init_stuff() :

$ibImgItems.bind('click.ibTemplate', function(clik_$ibImgItem) {
    clik_$ibImgItem.preventDefault();
    openItem($(this));
    return false;
});

, @Hans!; -)

+4
3

: , , , . , , , , : = -.

, :

$ibImgItems = $ibItems.find('span:first').filter(':contains(objToWhom_Id)');

:

$ibImgItems = $ibItems.find('span:first').filter(':contains(' + objToWhom_Id + ')');

?

: : , : equals = :

var object = { property: value, someOtherProperty: someOtherValue };
+2

JavaScript

TestExpression ? ValueIfTrue : ValueIfFalse

var i = 100, a = 100;
outerloop:
while(i > 0) {
  while(a > 0) {
   a++
   if(a>50) {
     break outerloop;
   }
  }
  i++
}

/

var MyObject = { keyName1: "value1", keyName2: "value2" }
+2

Although this is not as “clean” as the one provided by @Hans, here is another way to avoid the “tag” using another “external” filter:

var $ibImgItems = $ibItems
                     .filter(function(){
                          return $(this).find('span:first').filter(':contains('+objToWhom_Id +')');
                     });

I think it’s better with the “shortcut” logic to replace it, in this very special case. Just a thought.

Thanks again for all the contributions!

0
source

Source: https://habr.com/ru/post/1524281/


All Articles