Skip to content

Instantly share code, notes, and snippets.

@kreja
Created October 7, 2015 05:19
Show Gist options
  • Save kreja/2680363f42ffec42e279 to your computer and use it in GitHub Desktop.
Save kreja/2680363f42ffec42e279 to your computer and use it in GitHub Desktop.
给内置对象增加属性/方法
function specialString(){
var values = new String(arguments[0]);
values.startWith= function(text){
if(values.indexOf(text) == 0){
return true;
}else{
console.log(values,values.indexOf(text));
return false;
}
};
return values;
}
var a = new specialString('hello world');
console.log(a.startWith('hello')); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment