Created
October 7, 2015 05:19
-
-
Save kreja/2680363f42ffec42e279 to your computer and use it in GitHub Desktop.
给内置对象增加属性/方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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