----------------------------------------Vue.js------------------------------------------- Vue.js is a library for building interactive web interfaces. The goal of Vue.js is to provide the benefits of reactive data binding and composable view components with an API that is as simple as possible. - [Vuejs 初试](https://www.v2ex.com/t/259613) - [Element](http://element.eleme.io) Element,一套为开发者、设计师和产品经理准备的基于 Vue 2.0 的组件库,提供了配套设计资源,帮助你的网站快速成型。(饿了么推出 ----------------------------------------Javascrtip---------------------------------------- 自从我踏入web开发领域以来,Javascript一直都给我一种欣欣向荣乃至大势所趋的感觉。在linux中国上有看到 [github2016年度开源报告](https://octoverse.github.com/#frontpage)(Octoverse到底是什么意思...)。编程语言活跃度排名中,JS遥遥领先。另外我世界最强的PHP能排到第5还是满不错的。 “JavaScript, C#, and Go who have seen almost doubled growth. ” “Swift and TypeScript are up and coming with 3.5x growth. ” 看了微信文-如何面试前端工程师(作者是twitter的JeOam),进去看了下发现自己果然太嫩, 列一些JS要点吧,面试时有用。 ### Object Prototypes(对象原型) - 直接在对象的原型上添加方法是否安全? ```javascript String.prototypes.myfunction = function(){}; //方法原型的基础理解 ``` - 函数声明和函数表达式的区别? ECMAScript规范只明确了一点:函数声明必须带有标示符(Identifier)(就是大家常说的函数名称),而函数表达式则可以省略这个标示符。 如果function foo(){}是作为赋值表达式的一部分的话,那它就是一个函数表达式,如果function foo(){}被包含在一个函数体内,或者位于程序的最顶部的话,那它就是一个函数声明。 还有一种函数表达式不太常见,就是被括号括住的(function foo(){}),他是表达式的原因是因为括号 ()是一个分组操作符,它的内部只能包含表达式。 你可能会想到,在使用eval对JSON进行执行的时候,JSON字符串通常被包含在一个圆括号里:eval('(' + json + ')'),这样做的原因就是因为分组操作符,也就是这对括号,会让解析器强制将JSON的花括号解析成表达式而不是代码块。 - [Use of 'prototype' vs. 'this' in JavaScript?](http://stackoverflow.com/questions/310870/use-of-prototype-vs-this-in-javascript?rq=1) 例子理解: [add-a-method-to-prototype](http://stackoverflow.com/questions/26473952/add-a-method-to-prototype) 查询相关资料的时候看到了stackoverflow上的一个关于prototype的问题,看了下代码,又Sprite又是Dragon,po主在开发页游吧,稍微理解到js的游戏开发思路。 po主这里定义了一个Sprite构造函数,然后想定义一个从Sprite派生的Dragon构造函数,因为他最后return object,所以到这里其实Dragon已经变成了工厂函数(factory function)而非构造函数了(constructor function),因为构造函数并不创建对象。 为了解决这个问题,需要用到.call()的方法在最开始初始化。 并且为了保证原型链(prototype chain)的正确性,需要让Dragon.prototype继承Sprite.prototyp。也就是Object.create(); ### 参数argument - 对argument object的理解:[console.log在webkit中apply](http://www.cnblogs.com/dishuostec/archive/2011/12/13/2286327.html) 下面来写调试函数log(),且要求在每个log消息前加上前缀(例如app ```javascript var DEBUG = true; function log(){ if(DEBUG){ //因为argument是伪数组所以需要把它转换为标准数组。 var args = Array.prototype.slice.call(arguments); if(argument){ args.unshift('app');console.log.apply(console,args);} } } ``` ### context与this的理解 - [Understanding Scope and Context in JavaScript](http://ryanmorr.com/understanding-scope-and-context-in-javascript/) - 方法执行时上下文是window还是什么。 - apply(),call(),bind()的理解 - 老版本浏览器不支持bind方法: ```javascript Function.prototype.bind=Function.prototype.bind || function(context){ var self = this; return function(){ return self.apply(context,arguments); }; } ``` ### 写弹出窗口(Overlay library) - 遮罩层:position fixed与porition absolute的区别 - 内容居中:内容的宽高是否固定?css 绝对定位 :JS动态定位 - 冒泡机制考察:点击遮罩层关闭。 ```javascript $('.overlay').click(function(e){ //检查事件的触发对象与绑定对象是否一致 //确定事件不是从子元素里冒上来的 if (e.target == e.currentTarget) closeOverlay(); }); ``` ### 其他 性能,HTML5 API,AMD和CommonJS模块模型,构造函数,类型和盒子模型(box model); --------------------------------------my practice------------------------------------------ #### 想起了7月份很激动地去面试笔试的时候,发现连二分查找都不会。 分别练习了下二分查找算法和查重。 二分查找算法的空间复杂度是O(log n) 时间复杂度是O(1) Big O notation 是用于描述函数渐近行为的数学符号。更确切地说,它是用另一个(通常更简单的)函数来描述一个函数数量级的渐近上界 ```javascript var srr = [-1,1,1,1.2,5,23]; binarysearch(srr,23); isRepeat(srr); function isRepeat(arr){ hash = []; for (var i in arr) { if (hash[arr[i]]) return alert('repeat'); hash[arr[i]] = true; } return alert('no repeat'); } function binarysearch(arr,x) { var start = 0; var end = arr.length-1; var i = 0;//control while(i < 50 && end >= start){ var mi = parseInt((end+start)/2);i++; if(x == arr[mi]){ return alert(x+'的index是'+mi); }else if (x < arr[mi]) { end = mi-1; }else{ start = mi+1; } } return alert(x+'不在数组中'); } ```