创建实例对象 var dt = new Date(); //当前的时间---当前的服务器 console.log(dt); var dt = new Date("2017-08-12");//传入时间写法1 //传入的时间 console.log(dt); 传入时间也可以这样写: var dt = new Date("2017/08/12"); //传入时间写法2 //传入的时间 console.log(dt); //获取时间的对象 var dt = Date.no…
系统Max求最大值: var result= Math.max(10,20,30,40); console.log(result); 练习1:自己定义一个对象,实现系统的max的方法 //例子:自己定义一个对象,实现系统的max的方法 function MyMath() { //添加了一个方法 this.getMax = function () { //所有数字中的最大值 var max = arguments[0]; for (var i = 0; i < arguments.length…
引入: //计算两个数字的和 function f1(x, y) { return x + y; } //计算三个数字的和 function f2(x, y, z) { return x + y + z; } //计算四个数字的和 function f3(x, y, z, k) { return x + y + z + k; } //计算五个数字的和 function f4(a, b, c, d, e) { return a + b + c + d + e; } //计算六个数字的和 funct…
原型prototype 我们创建的每一个函数,解析器都会向函数中添加一个属性prototype 这个属性,对应着一个对象,这个对象就是我们所谓的原型对象 1.如果函数作为普通函数调用prototype没有任何作用 2.当作为构造函数调用时,它所创建的对象中,都会有一个隐含的属性,指向该构造函数的原型对象. 隐含属性:__proto__ function MyClass(){ }; var mc = new MyClass(); console.log(mc.__proto__ == MyClas…
格式化后的指定格式的日期和时间,封装一个函数 function getDate() { var dt = new Date(); var year = dt.getFullYear(); var month = dt.getMonth(); var date = dt.getDate(); var hour = dt.getHours(); var minute = dt.getMinutes(); var second = dt.getSeconds(); month = month < 10…
JS的原型.原型链一直是比较难理解的内容,不少初学者甚至有一定经验的老鸟都不一定能完全说清楚,更多的"很可能"是一知半解,而这部分内容又是JS的核心内容,想要技术进阶的话肯定不能对这个概念一知半解,碰到问题靠"猜",却不理解它的规则! prototype 只有函数有prototype属性 let a = {} let b = function () { } console.log(a.prototype) // undefined console.log(b.pro…