![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
JavaScript
文章平均质量分 75
张小水儿
这个作者很懒,什么都没留下…
展开
-
JavaScript中的apply和call
刚刚接触到apply和call方法时,对他们两个的理解十分的模糊,最近在联系的过程中对apply和call有了更清晰的理解了,我把我对这个问题的理解记录在这里,如果有什么不对的或者说的不清楚的地方还请大家指出,谢谢1.apply apply的语法:Function.apply(obj, args)apply可以用另一个对象代替当前对象。apply方法有两个参数:ob原创 2015-12-11 15:08:45 · 346 阅读 · 0 评论 -
JavaScript事件代理
事件代理 (event delegation)JavaScript事件代理是一种简单地技巧,通过它我们可以把事件处理器添加到一个父级元素上,这样就避免了把事件处理器添加到多个子集元素上事件代理利用了两个在JavaScript事件中常会被忽略的两个特性:事件冒泡以及目标元素举个例子:现在页面中有一个列表结构 1 2 3 4 现在需要给每个li添加点击事件原创 2015-12-25 19:32:17 · 339 阅读 · 0 评论 -
JavaScript中的类与对象
对象是对客观事物的抽象类是对对象的抽象JavaScript是基于对象的语言,它拥有许多创建类和对象的方法JavaScript中允许我们在对象创建之后进行定义对象的属性,我们可以这样来写//定义一个box对象var box = new Object;//对对象的属性进行定义box.color = 'blue';box.size = 30;box.number =原创 2015-12-09 19:52:22 · 278 阅读 · 0 评论 -
数据结构:JavaScript实现列表
列表是一组有序的数据,每个列表中的数据项称为元素在javascript中,列表中的元素可以是任意数据类型,列表中可以保存多少元素并没有实现限定,实际使用时元素的数量受到程序内存的限制代码以及解释如下function List(){ this.listSize = 0; this.pos = 0; //初始化一个空数组来保存列表元素 this.dataStore = []; t原创 2016-01-27 22:17:12 · 476 阅读 · 0 评论 -
数据结构:JavaScript实现栈
栈是一种特殊的列表栈中的元素只能从列表的一端进行访问,这一端被我们称作栈顶栈是一种后入先出(LIFO last-in-first-out)的数据结构代码如下function Stack(){ //保存栈内元素 this.dataStore = []; //记录栈顶位置 this.top = 0; //向栈顶压入一个新元素 this.push = push; /原创 2016-01-28 20:42:51 · 326 阅读 · 0 评论 -
数据结构:JavaScript实现队列
队列是一种列表,不同的是队列只能在队尾插入元素,在队首删除元素。队列用于存储按顺序排列的数据,先进先出,可以将队列想象成在食堂排队打饭的人群,排在队伍最前面的人第一个打饭,新来的人只能在最后面排队,直到轮到他们为止。队列是一种先进先出(First-In-First-Out,FIFO)的数据结构代码如下function Queue(){ this.dataStore = [];原创 2016-01-29 11:50:14 · 359 阅读 · 0 评论 -
一组JavaScript试题(包含一些容易混淆的知识点)
今天刷知乎的时候无意间发现的一组JavaScript试题,做了一下...共35道,对14,错17,十分惨痛,在这里整理一下这些题目,梳理一下其中的知识点JavaScript专业八级测试,你能做对几道?1.> ["1", "2", "3"].map(parseInt)[ 1, NaN, NaN ]这里涉及到的知识点是parseInt函数parseInt函数接受两个参数分别为Stri原创 2016-03-01 18:09:26 · 937 阅读 · 0 评论 -
数据结构:JavaScript实现链表
链表是由一组节点组成的集合,每个节点都使用一个对象的引用指向它的后继。数组元素靠他们的位置进行引用,链表元素则是靠互相之间的关系进行引用。一.一个基本的链表一下是一个基于对象的链表的代码以及解释//Node类包含两个属性,element用来保存节点上的数据,next用来保存指向下一个节点的链接function Node(element){ this.element =原创 2016-01-31 15:04:08 · 324 阅读 · 0 评论 -
数据结构:JavaScript实现字典
字典是一种以键值对形式存储数据的数据结构,这里的键是指用来查找的东西,值是查找得到的结果代码如下function Dictionary(){ this.add = add; this.dataStore = new Array(); this.find = find; this.remove = remove; this.showAll = showAll; this.coun原创 2016-01-31 18:38:22 · 327 阅读 · 0 评论 -
数据结构:JavaScript实现散列
一.引言散列是一种常用的数据存储技术,散列后的数据可以快速的插入或者取用,散列使用的数据结构叫做散列表。我们的散列是基于数组进行设计的,数组的长度是事先设定的,如有需要可以随时增加,,所有元素根据该元素对应的键,保存在数组的特定位置,该键和字典中的键是类似的概念,使用散列表来存储数据时,通过一个散列函数将键映射为一个数字,这个数字的范围是0到散列表的长度。需要注意的是:散列表中的数组应原创 2016-02-02 12:41:16 · 1323 阅读 · 0 评论 -
数据结构:JavaScript实现各种排序
这里首先写了一个数组测试平台,用于生成随机的数组进行排序的测试function CArray(numElements){ this.dataStore = []; this.pos = 0; this.numElements = numElements; this.insert = insert; this.toString = toString; this原创 2016-02-17 15:37:58 · 356 阅读 · 1 评论 -
数据结构:JavaScript实现二叉查找树
二叉树是一种特殊的树,它的子节点个数不超过两个。二叉查找树是一种是一种特殊的二叉树,相对较小的值保存在左节点中,较大的保存在右节点中,这一特性使得查找效率大大提高。首先我们需要的对象就是Node,它包含了左子节点,右子节点以及存储的数据,另外还有一个方法来读取数据function Node(data, left, right){ this.data = data; th原创 2016-02-20 16:47:57 · 418 阅读 · 0 评论 -
关于JavaScript作用域的练习题
var y = 'global';function test(x){ if(x){ var y ='local'; } return y;}console.log(test(true));输出:local与C++所不同的是,JavaScript中的作用域是函数作用域,而不是块级作用域,第一句话中的y的作用域是全局,而函数中y的作用域是test函数,上面的程序会返回test原创 2015-12-23 15:17:56 · 3046 阅读 · 0 评论 -
几个JavaScript面试题
1.问题:`foo`的值是什么?var foo = 10 + '20';foo = 10202.下面的语句的返回值是什么?"i'm a lasagna hog".split("").reverse().join("");goh angasal a m'isplit()将字符串分割成数组reverse()用来颠倒数组中的元素,该方法会改变原来原创 2015-12-22 20:18:59 · 2074 阅读 · 0 评论 -
leetcode (228) Summary Ranges js代码实现
Summary RangesGiven a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].给出一个数组,找出其中连续的区间,比如例子中的,0到2原创 2015-12-21 13:30:57 · 359 阅读 · 0 评论 -
leetcode (35) Search Insert Position js代码实现
Search Insert PositionGiven a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume原创 2015-12-20 19:29:39 · 618 阅读 · 0 评论 -
leetcode (260) Single Number III js代码实现
Single Number IIIGiven an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.原创 2015-12-20 17:38:40 · 282 阅读 · 0 评论 -
leetcode (137) Single Number II js代码实现
Single Number IIGiven an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you im原创 2015-12-20 17:19:14 · 477 阅读 · 0 评论 -
leetcode (136) Single Number js代码实现
Single NumberGiven an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement i原创 2015-12-20 17:04:08 · 757 阅读 · 0 评论 -
leetcode (1) Two Sum js代码实现
Given an array of integers, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers such that they add up to the target, whe原创 2015-12-19 21:22:48 · 1486 阅读 · 0 评论 -
leetcode (5) Longest Palindromic Substring js代码实现
Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic s原创 2015-12-19 01:16:45 · 584 阅读 · 0 评论 -
leetcode(58)Length of Last Word js代码实现
Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is原创 2015-12-18 14:28:02 · 330 阅读 · 0 评论 -
leetcode(303)Range Sum Query - Immutable js代码实现
leecode(303)Range Sum Query - Immutable js代码实现原创 2015-12-18 14:21:28 · 397 阅读 · 0 评论 -
JavaScript继承方式
1.apply方法apply方法详情可以参考JavaScript中的apply和callapply方法同样也可以实现多继承示例代码function School(){ this.name = 'HEU'; this.showName = function(){ console.log(this.name); }}function Unit(){ th原创 2015-12-13 23:05:50 · 239 阅读 · 0 评论 -
JavaScript事件监听机制
初学JavaScript时,会用这样的方法监听事件 js事件监听机制 btn1 = document.getElementById("btn-1"); btn1.onclick = function(){ alert("第一次点击按钮"); } btn1.onclick = function(){ alert("第二次点原创 2015-12-16 20:42:49 · 555 阅读 · 0 评论 -
js数组去重
利用原生JavaScript实现数组去重方法一思想:创建一个新数组(结果数组),每次取原数组中的元素并检查结果数组中是否已经存在该元素,如果不存在,则将该元素加入该数组,否则,跳过该元素去检查下一个元素。代码:Array.prototype.unique1 = function(){ var result = [this[0]]; for(var i = 1; i < this原创 2016-03-31 15:42:03 · 402 阅读 · 0 评论