次のJavaScript
コードを実行すると、undefined
var ns=new String('hello world');
String.prototype.capitalAll=function(){
this.toUpperCase()
};
alert(ns.capitalAll()); // undefined
しかし、私が追加するreturn
と、それは値を返します
var ns=new String('hello world');
String.prototype.capitalAll=function(){
return this.toUpperCase() // added return
};
alert(ns.capitalAll()); // HELLO WORLD
return
こことすべての関数の最後になぜ必要なのか。私はreturn
多くのjavascript
フレームワークでの使用を見てきました。