先來看看面試題吧
今天早上的時(shí)候砚蓬,CTO發(fā)到釘釘中的截圖诈泼,一道道來吧
1、頁面導(dǎo)入樣式時(shí)析恢,使用<link> 和 @import有什么區(qū)別?
答:先說說link 和 @import都是什么秧饮,前端開發(fā)頁面三部分映挂,html頁面骨架泽篮,css豐富頁面顯示,js負(fù)責(zé)頁面事件邏輯交互柑船。然而在hmtl中引用css又存在三種方式帽撑,行內(nèi)、內(nèi)聯(lián)鞍时、外部引用油狂,link 和 @import 是引用外部css的兩種方法。
//link引入方式
<link type="text/css" href="style/common.css">
//@import引入方式
<style type=text/css>@import url("style/common.css")</style>
同樣是兩種方式的引用寸癌,究竟區(qū)別在哪里
1、引用范圍不同:link功能性更強(qiáng)弱贼,不僅能引用css文件蒸苇,而@import 只能引用css文件。
2吮旅、加載時(shí)機(jī):link按照在html中由上到下的順序加載溪烤,而@import則需要等待頁面完全載人后才加載。
2庇勃、css權(quán)重是怎么計(jì)算的檬嘀?
答:在上面那道題上寫到了CSS的引用方式,三種 行內(nèi)责嚷、內(nèi)聯(lián)鸳兽、外部引用。不是簡單的行內(nèi)>內(nèi)聯(lián)>外部引用罕拂,也不是簡單的ID>class>標(biāo)簽揍异,總結(jié)來說
0、使用!important標(biāo)記爆班,權(quán)重最高
1衷掷、行內(nèi)樣式優(yōu)先級其次。
2柿菩、ID選擇器其次戚嗅。
3、類選擇器枢舶、標(biāo)簽選擇器根據(jù)組合情況判斷權(quán)重懦胞。
4、若優(yōu)先級相同祟辟,文檔下面的樣式會對上面的同級樣式進(jìn)行覆蓋医瘫。
3、怎樣用js實(shí)現(xiàn)多重繼承旧困?
答:先說一下什么是多重繼承醇份,多重繼承就是一個(gè)子類可以繼承多個(gè)父類的方法或者屬性稼锅,
//定義父類
function parent () {
this.name = 'father';
this.age = '50';
this.jump = function () {
return this.name+'50米';
}
}
//定義父類原型方法
parent.prototype.swim = function() {
// body...
return this.name+'this is swim';
};
//定義兄父類
function uncle () {
this.name = 'father2';
this.age = '45';
this.color = 'blue';
this.height = '2.3';
this.fly = function () {
return this.name+'2300米~';
}
}
//定義兄父類原型方法
uncle.prototype.walk = function() {
// body...
return this.name+'this is walk';
};
//繼承父類、兄父類的屬性和方法
function child () {
// body...
parent.call(this);
uncle.call(this);
}
for (var i in parent.prototype) {
child.prototype[i] = parent.prototype[i];
};
for (var i in uncle.prototype) {
child.prototype[i] = uncle.prototype[i];
};
var xiaoming = new child();
console.log(xiaoming.name+'&xiaoming.name'); //father2&xiaoming.name
console.log(xiaoming.color+'&xiaoming.color'); //blue&xiaoming.color
console.log(xiaoming.fly()); //father22300米~
console.log(xiaoming.walk()); //father2this is walk
4僚纷、node.js回調(diào)套回調(diào)太麻煩矩距,打算怎么幫他?
答:解決異步回調(diào)es6的promise怖竭,nodejs基于谷歌的V8引擎支持es6锥债,解決異步連續(xù)回調(diào)的繁瑣.
所謂promise,簡單來說就是一個(gè)容器內(nèi)部包含了未來才會結(jié)束的事件痊臭,從語法上講promise是一個(gè)對象哮肚,從它可以獲取異步操作的消息
阮大神的解釋,專業(yè)广匙,簡潔易懂
var FS = require('fs');
const SERVER_DIR = _dirname;
var promise = new Promise(function (resolve,reject) {
FS.readFile(SERVER_DIR+'/../web/index.html','utf8',(error,html) =>{
if(err){
reject(error);
}else{
resolve(html);
}
} )
})
promise.then(function (html) {
response.end(html);
}).catch(function (error) {
response.end('服務(wù)器出錯(cuò)')
})
5允趟、寫一個(gè)js函數(shù),輸入一個(gè)0<x<99999999的整數(shù)x,返回一個(gè)字符串鸦致,標(biāo)識其漢語讀法潮剪?
function count () {
this.num = ['零','一','二','三','四','五','六','七','八','九','十'];
this.dif = ['','十','百','千'];
this.unit = ['','萬','億'];
this.empty = [];
this.shell = [];
};
count.prototype.Chinese = function(x) {
this.params = String(x);
this.reverseArr();
this.compliteData();
return this.printStr();
};
//生成倒序數(shù)組
count.prototype.reverseArr=function () {
var p = this.params;
for (var i = 0; i < p.length; i++) {
this.empty.push(p[i]);
};
this.empty.reverse();
};
//組合數(shù)據(jù)
count.prototype.compliteData= function () {
for (var i = 0; i < this.empty.length; i++) {
if(i%4){
//判斷是否為0;
if(Number(this.empty[i])){
this.shell.push(this.num[Number(this.empty[i])]+this.dif[i%4]);
};
}else{
if(Number(this.empty[i])){
this.shell.push(this.num[Number(this.empty[i])]+this.dif[i%4]+this.unit[i/4]);
}else{
//加萬分唾、億單位
this.shell.push(this.unit[i/4]);
};
};
};
this.shell.reverse();
};
//輸出字符串抗碰;
count.prototype.printStr = function () {
var str = '';
for (var i = 0; i < this.shell.length;i++) {
str += this.shell[i];
};
return str;
};
var obj = new count();
obj.Chinese(12000554); //一千二百萬五百五十四
6、說服老板不使用react绽乔,而選擇vue弧蝇?
答:這個(gè)問題隨便聊聊,隨便聊聊折砸,項(xiàng)目中使用的是vue捍壤,更趨向于vue的優(yōu)勢,來趨避react鞍爱,vue鹃觉,react的區(qū)別,學(xué)習(xí)成本睹逃,維護(hù)周期盗扇,開發(fā)周期,人力成本沉填,最終的產(chǎn)品優(yōu)劣疗隶,與框架相關(guān)的整套配套工具。vue與react的核心思想不同翼闹,vue是數(shù)據(jù)為核心斑鼻,通過ES5的object.defineProperty 屬性完成的數(shù)據(jù)的雙向驅(qū)動(dòng)。react的核心為復(fù)用話極高的組件化核心猎荠,一切皆組件坚弱。從學(xué)習(xí)成本來講蜀备,react的學(xué)習(xí)曲線是頗高的,vue相對來說更加直觀荒叶。由于學(xué)習(xí)成本的上升碾阁,開發(fā)周期必然的漫長。配套工具來說react是facebook團(tuán)隊(duì)開發(fā)的些楣,一直在維護(hù)脂凶,社區(qū)同樣非常活躍愁茁,相關(guān)配套較多蚕钦,只是個(gè)人理解、個(gè)人理解鹅很。
寫的不好的地方還望大家及時(shí)反饋與糾正冠桃,本著共同學(xué)習(xí)與進(jìn)步宗旨不斷前進(jìn)!5勒!