js
_AZU
生活没有你想象得那么好,但也不会像你想象得那么糟。
展开
-
浅拷贝和深拷贝
一. 浅拷贝1. for...invar obj = { name: '小明', age: 18}var newObj = {}for (var k in obj) { newObj[k] = obj[k]}2.... 展开运算符var newObj = { ...obj }3. Object.assigncvar newObj = Object.assign({}, obj);二. 深拷贝1.JSON.stringify()...原创 2020-11-16 16:56:05 · 163 阅读 · 0 评论 -
call、apply、bind方法的应用
1. call作用:改变 this 指向,调用函数传入参数。语法:function.call(this, arg1, arg2, ...)应用:子构造函数继承父构造函数的属性function Father (surname) { this.surname = surname;}function Son (surname) { // 改变父构造函数的中 this 为子构造函数中的 this,并给该属性传递值。 Father.call(this, surnam原创 2020-11-12 14:35:13 · 109 阅读 · 0 评论 -
js 数组去重的简单方法
1. for + indexOfvar arr = [1, 1, true, true, 'false', 'false'];var newArr = [];for(var i = 0; i < arr.length; i++){ if(newArr.indexOf(arr[i]) === -1){ newArr.push(arr[i]) }}...原创 2019-11-01 18:05:27 · 139 阅读 · 0 评论 -
H5页面获取用户当前地理位置
通过腾讯H5前端地理位置模块,来获取用户当前地理位置。<!-- 引入腾讯模块CDN --><script type="text/javascript" src="https://3gimg.qq.com/lightmap/components/geolocation/geolocation.min.js" ></script> // 调用qq_positi...原创 2018-04-28 11:08:54 · 11766 阅读 · 2 评论 -
函数的 call、apply、bind 方法
call 和 apply 用来执行函数,并改变 this 的指向(第一个参数),同时用指定函数的参数。call 与 apply 唯一的区别就是, call 接受的是参数列表,apply 接受的是参数数组。var str = 'window';var obj = {str: 'obj'}function fun() {console.log(this.str);...原创 2018-04-28 16:54:39 · 196 阅读 · 0 评论 -
Date 对象一些使用技巧
Date 对象使用小技巧1、获取指定日期new Date('2018/11/11 11:11:11'); // 时间为2018年11月11日 11时11分11秒new Date(2018,11,11,11,11,11); // 时间为2018年12月11日 11时11分11秒2、将Date对象转换时间字符串new Date().toLocaleDateString(); //...原创 2019-01-23 13:39:07 · 297 阅读 · 0 评论 -
node.js 爬取腾讯地图API全国行政区数据
使用 vue + element cascader级联选择器做城市选择器(可查看另一篇文章),需要全国行政区数据。github地址:https://github.com/username-xu/node.js-districtsconst fs = require('fs')// 请求模块,文档可参考:https://www.jianshu.com/p/1432e0f29abdco...原创 2019-05-20 17:28:44 · 1741 阅读 · 0 评论 -
vue + element cascader级联选择器编写城市选择器
需求:1、城市选择2、城市输入实现:html<el-cascader :options="options" change-on-select filterable @change="handleChange"></el-cascader>jsimport cities from '@/common/c...原创 2019-05-15 15:36:41 · 4838 阅读 · 2 评论 -
node.js爬取国家统计局全国行政区数据
github地址:https://github.com/username-xu/node-districtsconst fs = require('fs');// 网络请求,文档可参考:https://www.jianshu.com/p/1432e0f29abdconst superagent = require('superagent');// 设置编码格式,文档:https:/...原创 2019-05-22 17:09:26 · 683 阅读 · 1 评论