var something = [1, 2, 3, 4, 5];
something.length = 0;
var a = {};
var output = {function() {
delete x;
return x;
}}();
console.log(a);
delete๋ ๊ฐ์ฒด์์ key, value๋ฅผ ์ง์ธ๋ ์ฌ์ฉํ๋ค. ์ฉ๋๊ฐ ์๋ชป์ฐ์ฌ์ ธ ์๋ค.
var Employee = {
company: 'xyz'
}
var emp1 = Object.create(Employee);
// emp1 = {}
// __proto__ : company: 'xyz';
delete emp1.company;
// emp1์ ์๋ company๋ฅผ ์ง์ธ๋ ค๊ณ ํ๋๋ฐ emp1์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
// delete emp1.__proto__.company
// ์ด๋ ๊ฒ ํ๋ฉด Employee์ ์๋๊ฒ ์ง์์ง๋ค. ์๋ฆ..
console.log(emp1.company);
function myFunc() {
console.log(this.message);
}
myFunc.message = 'Hi John';
console.log(myFunc()) // this๋ window๊ณ console์ undefined
function Person(names, age){
this.names = name || "John";
this.age = age || 24;
this.displayName = function () {
console.log(this.names);
};
}
Person.names = "John2";
Person.displayName = function () {
console.log(this.names);
};
var person1 = new Person("John3");
person1.displayName();
Person.displayName();
function passWordMngr() {
var password = '12345678';
this.userName = 'John';
return {
pwd: password
};
}
var userInfo = passWordMngr();
console.log(userInfo.pwd); // '12345678'
console.log(userInfo.userName); // undefined