let a = {}, b = '0', c = 0;
a[b] = '123'
a[c] = '234'
console.log(a[b])
let a = {}, b = Symbol('1'), c = Symbol('1');
a[b] = 123
a[c] = 234
console.log(a[b])
let a = {}, b = {age: 18}, c = {age: 19};
a[b] = 123
a[c] = 234
console.log(a[b])
let test = (function (i) {
return function () {
alert(i*=2)
}
})(2)
test(5)
var a = 0, b = 0
function A(a) {
A = function(b) {
console.log(a + b++)
}
console.log(a++)
}
A(1)
A(2)
function Foo() {
getName = function() {
console.log(1)
}
return this
}
Foo.getName = function () {
console.log(2)
}
Foo.prototype.getName = function () {
console.log(3)
}
var getName = function() {
console.log(4)
}
function getName() {
console.log(5)
}
Foo.getName()
getName()
Foo().getName()
getName()
new Foo.getName()
new Foo().getName()
new new Foo().getName()
async function async1() {
console.log('async1 start')
await async2()
console.log('async1 end')
}
async function async2() {
console.log('async2')
}
console.log('start')
setTimeout(function(){
console.log('setTimeout')
}, 0)
async1()
new Promise((resolve)=>{
console.log('Promise1')
resolve()
}).then(()=>{
console.log('Promise2')
})
console.log('end')
function A() {
alert(1)
}
function Func() {
A = function() {
alert(2)
}
return this
}
Func.A = A
Func.prototype = {
A:()=>{
alert(3)
}
}
A()
Func.A()
Func().A()
new Func.A()
new Func().A()
new new Func().A()
当啊等于什么的时候,下面条件成立
if(a == 1 && a == 2 && a == 3) {
console.log('条件成立')
}
第一种方法:
let a = {
i: 0,
toString() {
return ++this.i
}
}
第二种方法:
let a = {
i: 0,
valueOf() {
return ++this.i
}
}
第三种方法:
let i = 0
Object.defineProperty(window, 'a', {
get() {
return ++i
}
})
第四种方法:
let a = [1, 2, 3]
a.toString = a.shift
let x = 2
let y = {
x: 3,
z:(function(x){
this.x*=x
x+=2
return function(n) {
this.x*=n
x+=3
console.log(x)
}
})(x)
}
let m = y.z
m(4)
y.z(5)
console.log(x,y.x)
function fn(a, c) {
console.log(a)
var a = 123
console.log(a)
console.log(c)
function a() {}
if(false) {
var d = 678
}
console.log(d)
console.log(b)
var b = function () {}
console.log(b)
function c() {}
console.log(c)
}
fn(1, 2)
var name = 222
var a = {
name: 111,
say: function () {
console.log(this.name)
}
}
var fun = a.say
fun()
a.say()
var b = {
name: 333,
say: function (fun) {
fun()
}
}
b.say(a.say)
b.say = a.say
b.say()