js基础
文章平均质量分 53
js基础知识
花裤衩-格子衫
这个作者很懒,什么都没留下…
展开
-
slice substring substr 区别
slice substring substr 区别原创 2022-06-22 10:51:05 · 96 阅读 · 0 评论 -
每日一题
2021-03-11 微信红包算法 function getWechatRedPacket(totalMoney, totalPeople) { let minMoney = 0.01; let maxMoney; let currentMoney; let sumList = []; while(totalPeople > 1) { maxMoney = totalMoney * 2.0 / totalPeople; currentMoney = Math.random() * m原创 2021-03-11 18:37:50 · 133 阅读 · 0 评论 -
js求值策略
1.按值传递, 是个copy,内部不会影响外部。 const a = { index: 1 }; function foo(obj) { obj.index = 2; } foo(a); console.log(a.index); // 1 2.按引用传递, 变量对象的指针都给了它。 const a = { index: 1 }; function foo(obj) { obj = { a: 2}; } foo(a); console.log(a); // { a: 2.原创 2020-12-10 00:51:18 · 123 阅读 · 0 评论 -
js-参数求值策略
1.按值传递 1.对象传递过去,不论函数内部如何修改,外部的参数都不变。 2.按引用传递,对于一个复杂的对象有性能问题。 1.就是共享一个指针,函数内部赋值或者修改属性都会影响到外部对象,不可控。 3.按共享传递。 1.可以看作一个构造函数,函数内部赋值不会影响外面的对象,而修改对象的属性会影响到外部的对象。 foo value: addr(0xFF) => {x: 100, y: 200} (address 0xFF) 0xFF) ...原创 2020-07-13 00:07:01 · 118 阅读 · 0 评论 -
js中call、apply、bind实现
bind实现函数柯里化来实现的 // 常见的形式this.onPress.bind(this,params1,params2); context 是个函数 Function.prototype.bind = function (context) { // 1设置变量 let _this = this || window; // 1拿到参数 let _args = Array.prototype.slice.call(arguments,1); return function() { _this原创 2020-05-18 02:11:20 · 104 阅读 · 0 评论 -
js原型--__proto__ 和constructor以及prototype关联关系
function Foo() {}; let f1 = new Foo(); __proto__ 一层一层的找。 /** * __proto__ 跟原型父对象有关主要针对属性。(最顶级的原型对象Object.prototype)。Object.prototype.__proto__ == null * constructor *解释了这个类;原型对象有一个constructor属性,指向该...原创 2020-04-27 23:42:50 · 133 阅读 · 0 评论 -
数组去重复数据
1.Set去重 function useSet(array = [1,2,4,3,5,1,2]) { return Array.from(new Set(array)) // return [...new Set(array)]; } 2.使用includes function useIncludes(array = [1,2,4,3,5,1,2]) { let newAr...原创 2020-04-27 23:28:57 · 157 阅读 · 0 评论