This file contains hidden or 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
var objectEx = { | |
prop1: 'k', | |
prop2: 1, | |
prop3: 'Hello' | |
}; | |
console.log(objectEx.hasOwnProperty('prop1'));//true μΆλ ₯ | |
console.log(objectEx.hasOwnProperty('prop4'));//false μΆλ ₯ | |
console.dir(objectEx); |
This file contains hidden or 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 myAdd(){ | |
console.dir(arguments); | |
Array.prototype.shift.apply(arguments); | |
console.dir(arguments); | |
} | |
myAdd(1,2,3,4); |
This file contains hidden or 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 animal(name){ | |
this.name = name; | |
} | |
var dog = {}; | |
animal.apply(dog,['James']);//animal.call(dog,'James'); μ κ°λ€. | |
console.dir(dog); |
This file contains hidden or 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
var a = 10;//μ μ λ³μ a μμ± | |
var object = { | |
a: 1, | |
func1: function() { | |
var that = this;//that λ³μμ this μ μ₯ | |
this.a += 1; | |
console.log('func1: ' + this.a); | |
var func2 = function () { | |
that.a += 1; | |
console.log('func2: ' + that.a); |
This file contains hidden or 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
var a = 10;//μ μ λ³μ a μμ± | |
var object = { | |
a: 1, | |
func1: function() { | |
this.a += 1; | |
console.log('func1: ' + this.a); | |
var func2 = function () { | |
this.a += 1; | |
console.log('func2: ' + this.a); | |
var func3 = function () { |
This file contains hidden or 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
var my = { | |
name: 'my', | |
sayName() { | |
console.log(this.name); | |
} | |
}; | |
var other = { | |
name: 'other' | |
}; |
This file contains hidden or 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 average() { | |
var sum = 0; | |
for(var i = 0; i<arguments.length; i++) { | |
sum += arguments[i]; | |
} | |
return sum/arguments.length; | |
} | |
average(1,2,3,4,5);//3 λ°ν |
This file contains hidden or 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 average(arg1, arg2, arg3) { | |
return (arg1 + arg2 + arg3)/3; | |
} | |
average(1);//NaN | |
average(1,2);//NaN | |
average(1,2,3);//2 |
This file contains hidden or 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 person (name){ | |
this.name = name; | |
} | |
console.dir(person.prototype); | |
console.dir(person.prototype.constructor); |
This file contains hidden or 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
var add = function(a,b) { | |
return a + b; | |
}; | |
add.k = 0; | |
console.log(add.k);//0 μΆλ ₯ |