Home  >  Article  >  Web Front-end  >  How to override padleft method in js

How to override padleft method in js

亚连
亚连Original
2018-05-17 10:32:342741browse

Please look at the code below

//重写padleft方法
        String.prototype.PadLeft = function (len, charStr) {
            var s = this + '';
            return new Array(len - s.length + 1).join(charStr) + s;
        }

##The above is what I compiled for everyone to rewrite padleft in js Method, I hope it will be helpful to everyone in the future.

Related articles:

What are the inheritance methods in js

How to pass two in JS onclick Specific steps for giving parameters to JS methods

In-depth explanation of js overwriting original methods and providing rewriting methods

The above is the detailed content of How to override padleft method in js. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn