Javascript 如何将函数的参数放在开头

Javascript 如何将函数的参数放在开头,javascript,Javascript,我这样写我的函数:truncate('helloworld!,5) 但是我想这样写我的函数:'helloworld!'。截断(5) 函数截断(str,num){ if(str.length使用prototype对象扩展方法 String.prototype.truncate = function(num){ if (this.toString().length <= num) return this.toString(); return this.toString().sl

我这样写我的函数:
truncate('helloworld!,5)

但是我想这样写我的函数:
'helloworld!'。截断(5)

函数截断(str,num){

if(str.length使用prototype对象扩展方法

String.prototype.truncate = function(num){
    if (this.toString().length <= num) return this.toString();
    return this.toString().slice(0,num)
};
'Hello World!'.truncate(5); //  Hello
String.prototype.truncate=函数(num){
if(this.toString().length
String.prototype.truncate = function(num){
    if (this.toString().length <= num) return this.toString();
    return this.toString().slice(0,num)
};
'Hello World!'.truncate(5); //  Hello