Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2cab458

Browse files
docs : update 3-5.js
1 parent 5509a95 commit 2cab458

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎생활코딩-3.객체지향/3-5-표준내장객체.js‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,20 @@ Math
1515
Date
1616
RegExp
1717
가 있다.
18-
*/
18+
*/
19+
20+
// 이러한 표준 내장 객체에 원하는 기능을 확장해서 사용할 수 있다.
21+
// 아래와 같이, 배열에 관한 함수를 선언한 것을,
22+
var arr = new Array('관자제보살', '천수보살', '여의륜보살', '대세지보살', '수월보살')
23+
function getRandomValueFromArray(haystack){
24+
var index = Math.floor(haystack.length*Math.random())
25+
return haystack[index]
26+
}
27+
console.log(getRandomValueFromArray(arr))
28+
29+
// 아래처럼, 배열 객체에 함수를 메서드로 포함시킬 수 있다.
30+
Array.prototype.rand = function(){
31+
var index = Math.floor(this.length*Math.random())
32+
return this[index]
33+
}
34+
console.log(arr.rand())

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /