I’m working on samsung SDK and modifying a javascript app for smart tv. I stumbled upon this piece of code and I don’t understand what if($('.menuButton').push()){... does. The native push function was not overwrited but this still works. I thought push will append an element to an array, but this doesn’t seem to be the case
if(direction==tvKey.KEY_ENTER){
if($('.menuButton').push()){
$('.simple_menu').slideDown('easy');
........
Calling
.push(x)on a JQuery selector acts the same as calling.push(x)on a normal array in Javascript.From W3Schools and the Mozilla Developer Network:
and
If no arguments are passed to
.push(), then the array is left as-is, and the length is still returned.So what is happening here is the array length is being returned and used to evaluate the
ifstatement.Example:
The following will return the number of
ptags:But Beware:
The
.pushmethod for JQuery objects is marked for internal use only and thus should not be depended on.