Jquery syntax and regex operators -


can 1 explain || operator mean in following line - mean or. if means or how 1 interpret line because doesn't make sense:

d = a.attr("data-template") || "<% remainingchars %> characters left" 

below code taken

$("[maxlength]").each(function (ind, elem) {     var b = $(this),          = b.parent(".form-group").find(".caption"),         d = a.attr("data-template") || "<% remainingchars %> characters left"; 

and html:

<div class="form-group">     <small class="caption" data-template="<% remainingchars %> characters left">            150 characters left     </small>     <input type="text">                     </div> 

what second replace part of following regex , {{maxcount}} mean?

c = d.replace(/<% remainingchars %>/gi, g()).replace(/{{maxcount}}/gi, j); 

the code

d = a.attr("data-template") || "<% remainingchars %> characters left"

means: if a.attr("data-template") truthy assign value d otherwise d should equal "<% remainingchars %> characters left"

it written as:

if (a.attr("data-template")) {   d = a.attr("data-template"); } else {   d = "<% remainingchars %> characters left"; } 

or

d = a.attr("data-template") ? a.attr("data-template") : "<% remainingchars %> characters left" 

use of <% remainingchars %> , {{maxcount}} suggest kind of templating "language" although seems it's mix of handlebars/mustache ({{}}) , underscore, ejs... (possibly) (<% %>).


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -