function Foo() {}
function Bar() {}
function Baz() {}
Bar.prototype = Object.create(Foo.prototype)
Baz.prototype = Object.create(Bar.prototype)
let baz = new Baz()
console.log(Baz.prototype.isPrototypeOf(baz))
console.log(Bar.prototype.isPrototypeOf(baz))
console.log(Foo.prototype.isPrototypeOf(baz))
console.log(Object.prototype.isPrototypeOf(baz))
let o = {}
let a = []
o.prop = 'is enumerable'
a[0] = 'is enumerable'
console.log('-------------')
console.log(o.propertyIsEnumerable('prop'))
console.log(a.propertyIsEnumerable(0))
let arr = ['is enumerable']
console.log(arr.propertyIsEnumerable(0))
console.log(arr.propertyIsEnumerable('length'))
console.log(Math.propertyIsEnumerable('random'))
console.log(Math.propertyIsEnumerable('PI'))
console.log(this.propertyIsEnumerable('Math'))
let arr1 = []
arr1.propertyIsEnumerable('constructor')
function firstConstructor() {
this.property = 'is not enumerable'
}
firstConstructor.prototype.firstMethod = function() {}
function secondConstructor() {
this.method = function method () {return 'is enumerable'}
}
secondConstructor.prototype = new firstConstructor()
secondConstructor.prototype.constructor = secondConstructor
let obj = new secondConstructor()
obj.arbitraryProperty = 'is enumerable'
console.log('-------------')
console.log(obj.propertyIsEnumerable('arbitraryProperty'))
console.log(obj.propertyIsEnumerable('method'))
console.log(obj.propertyIsEnumerable('property'))
console.log(obj.propertyIsEnumerable('firstMethod'))
console.log(secondConstructor.prototype.isPrototypeOf(obj))
console.log(firstConstructor.prototype.isPrototypeOf(obj))
console.log(Object.prototype.isPrototypeOf(obj))
console.log(firstConstructor.prototype)
console.log(Function.prototype === Function.__proto__)
let obj1 = new Object()
obj1.propOne = null
console.log('------------')
console.log(obj1.hasOwnProperty('propOne'))
obj1.propTwo = undefined
console.log(obj1.hasOwnProperty('propTwo'))
obj1.prop = 'exist'
console.log(obj1.hasOwnProperty('prop'))
console.log(obj1.hasOwnProperty('toString'))
console.log(obj1.hasOwnProperty('valueOf'))
let buz = {
fog: 'stack'
}
for (let name in buz) {
if (buz.hasOwnProperty(name)) {
console.log('this is (' + name + ') for sure. Value: ' + buz[name])
} else {
console.log(name)
}
}
let foo = {
hasOwnProperty: function() {
return false
},
bar: 'Here be dragons'
}
console.log(foo.hasOwnProperty('bar'))
console.log(({}).hasOwnProperty.call(foo,'bar'))
console.log(Object.prototype.hasOwnProperty.call(foo,'bar'))
let str = new String('str')
console.log(str.hasOwnProperty('length'))
let arr2 = new Array()
console.log(arr2.hasOwnProperty('length'))
console.log(Math.hasOwnProperty('PI'))
console.log(str)
let obj3 = new Object()
console.log('--------------')
console.log(obj3.toString())
let obj4 = {name:'zhangsan'}
console.log(obj4.toString())
let toString = Object.prototype.toString
console.log(toString.call(new Date))
console.log(toString.call(new String))
console.log(toString.call(Math))
console.log(toString.call(undefined))
console.log(toString.call(null))
let array = ['a','b',33]
console.log('--------------')
console.log(array.valueOf() === array)
let date = new Date()
console.log(date.valueOf())
let num = 15.456
console.log(num.valueOf())
let str1 = '123456abc'
console.log(str1.valueOf())
let bool = true
console.log(bool.valueOf())
let newBool = new Boolean(true)
console.log(newBool.valueOf() === newBool)
let fun = function () {}
console.log(fun.valueOf() === fun)
let obj5 = {}
console.log(obj5.valueOf() === obj5)