【前端面试】字节跳动2019校招面经 - 前端开发岗(二)
生活随笔
收集整理的這篇文章主要介紹了
【前端面试】字节跳动2019校招面经 - 前端开发岗(二)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
【前端面試】字節(jié)跳動2019校招面經(jīng) - 前端開發(fā)崗(二)
因為之前的一篇篇幅有限,太長了看著也不舒服,所以還是另起一篇吧?一、 jQuery和Vue的區(qū)別
jQuery 輕量級Javascript庫Vue 漸進(jìn)式Javascript-MVVM框架
jQuery和Vue的對比
再說一些Vue相比jQuery而言所具有的優(yōu)勢
- 組件化開發(fā),提高代碼的復(fù)用
- 數(shù)據(jù)和視圖分離,便于維護(hù)和操作
- 虛擬DOM,在無需關(guān)心DOM操作的基礎(chǔ)上,依然提供了可靠的性能
二、 模擬jQuery的選擇器($())實現(xiàn)
源碼如下
(function(){jQuery = function( selector, context ) {// The jQuery object is actually just the init constructor 'enhanced'return new jQuery.fn.init( selector, context, rootjQuery );};if ( typeof window === "object" && typeof window.document === "object" ) {window.jQuery = window.$ = jQuery;} })();最簡單的方法
僅僅對于IE8及以上有效 (function(){var jQuery = function(selector){return document.querySelectorAll(selector);};window.jQuery = window.$ = jQuery; })();querySelectorAll()返回的是DOM原生element對象
而jQuery的選擇器返回的是jQuery的包裝對象,同時包含了原生DOM對象和一些jQuery的構(gòu)造函數(shù)所具有的屬性
稍微復(fù)雜一點的實現(xiàn)方法
(function(){var jQuery = function(selector){var result = {};if (selector.substring(0,1) === "#") {result = document.getElementById(selector.substring(1));// this.tqOjbect.data.push(elem);} else if (selector.substring(0,1) === ".") {result = document.getElementsByClassName(selector.substring(1));} else {result = document.getElementsByTagName(selector);}return result;};window.jQuery = window.$ = jQuery; })();三、jQuery的鏈?zhǔn)秸{(diào)用實現(xiàn)
var MyJQ = function(){} MyJQ.prototype = {css:function(){console.log("設(shè)置css樣式");return this;},show:function(){console.log("將元素顯示");return this;},hide:function(){console.log("將元素隱藏");}}; var myjq = new MyJQ(); myjq.css().css().show().hide();四、網(wǎng)絡(luò)模型知識
總結(jié)
以上是生活随笔為你收集整理的【前端面试】字节跳动2019校招面经 - 前端开发岗(二)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬虫外贸客户_python
- 下一篇: 好程序员前端分享使用JS开发简单的音乐播