2020-01-18 15:48:20 +08:00

108 lines
2.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// function add() {
// // 第一次执行时,定义一个数组专门用来存储所有的参数
// var _args = Array.prototype.slice.call(arguments);
// // 在内部声明一个函数利用闭包的特性保存_args并收集所有的参数值
// var _adder = function() {
// _args.push(...arguments);
// return _adder;
// };
// // 利用toString隐式转换的特性当最后执行时隐式转换并计算最终的值返回
// _adder.toString = function () {
// return _args.reduce(function (a, b) {
// return a + b;
// });
// }
// return _adder;
// }
// add(1)(2)(3) // 6
// add(1, 2, 3)(4) // 10
// add(1)(2)(3)(4)(5) // 15
// add(2, 6)(1)
// function f() {
// return 1
// }
// var obj = {
// c: true
// }
// var arr = []
// var obj1 = {
// a: 2,
// b: obj,
// c: arr,
// d:f,
// e:function () {
// return 1
// }
// }
// console.log(obj1)
// var test = JSON.parse(JSON.stringify(obj1))
// console.log(test)
// var test1 = Object.assign({}, obj1)
// console.log(test1)
// obj = {
// c: false
// }
// arr = ['w']
// obj1.b = []
// console.log(obj)
// console.log(obj1)
// console.log(test)
// console.log(test1)
// var obj = {
// // set a(val) {
// // this._a_ = val * 2
// // },
// // get a() {
// // return this._a_
// // },
// }
// Object.defineProperty(
// obj,
// 'a',
// {
// set: function(val) {
// this._a_ = val * 2
// },
// get: function() {
// return this._a_
// },
// writable: false,
// enumerable: true
// }
// )
// obj.a = 2
// console.log(obj)
// console.log(obj.a)
function Foo(who) {
this.me = who
}
Foo.prototype.indetify = function() {
return "I am" + this.me
}
function Bar(who) {
Foo.call(this, who)
}
Bar.prototype = Object.create(Foo.prototype)
Bar.prototype.speak = function() {
alert('Hello,'+ this.indetify() + '.')
}
var b1 = new Bar('b1')
var b2 = new Bar('b2')
b1.speak()
b2.speak()
var a = [1,2,3]
var b = [1,2,3]
var c = "1,2,3"
console.log(a == b)
console.log(a == c)
console.log(b == c)