Cannot Call the Underscore.String Function `lpad` for Error `Uncaught TypeError: _.lpad is not a function`

472 Views Asked by At

I want to call the function _.lpad('1', 2, '0') but chrome shows me that Uncaught TypeError: _.lpad is not a function. I already included the script tags in the HTML file like the following.

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/underscore.string/3.3.4/underscore.string.min.js"></script>

If I call console.log(_), it shows me:

>console.log(_)
function (n){return n instanceof m?n:this instanceof m?void(this._wrapped=n):new m(n)}

Can you tell me why and how to solve it?

1

There are 1 best solutions below

0
gu mingfeng On BEST ANSWER
s.lpad('1', 2, '0')

underscore.string export as window.s in browser