본문 바로가기
Research/Javascript

'_hash(input)'의 언더바? Private property

by RIEM 2022. 11. 25.
728x90
// HashTable Challenge : add set, get methods

class HashTable {
constructor(size){
// set memory size
this.data = new Array(size);
// [['grapes', 10000]]
}

// hash function
_hash(key) {
let hash = 0;
for (let i = 0; i < key.length; i++) {
hash = (hash + key.charCodeAt(i) * i) % this.data.length
}
return hash;
}


}

const myHashTable = new HashTable(50);
myHashTable.set('grapes', 10000);
myHashTable.get('grapes');

Private property

_hash? it is a kind of meaning-less property such as ‘You better not use this’ to other developers.

 

참고할 것들

https://javascript.info/private-protected-properties-methods

https://stackoverflow.com/questions/22156326/private-properties-in-javascript-es6-classes

 

728x90

댓글