Skip to content

Instantly share code, notes, and snippets.

@scplay
Last active June 12, 2018 07:06
Show Gist options
  • Save scplay/8c692364356174c0362bddb65b604332 to your computer and use it in GitHub Desktop.
Save scplay/8c692364356174c0362bddb65b604332 to your computer and use it in GitHub Desktop.
JSExam
var arr = [0, 1, 2];
function doSomeThing(arr) {
arr[0] = 10;
arr[1] = 10;
arr[2] = 10;
return arr;
};
var new_arr = doSomeThing(arr);
console.log(new_arr === arr); // true or false ?
var obj = {
a : 1,
b : 2
};
function doOtherThing(obj) {
obj = {a: 1};
obj.b = 2;
return obj;
};
var new_obj = doOtherThing(obj);
console.log(new_obj === obj); // true or false ?
var v = 1;
setTimeout(v => {
console.log(v);
setTimeout(v => {
console.log(v);
}, 0, 3);
}, 1010, 2);
setTimeout(v => {
console.log(v);
setTimeout(v => {
console.log(v);
}, 1000, 5);
}, 0, 4);
console.log(v);
// 请列出所有 console.log(v) 的值以及其输出的顺序
// 数据如下
var traces = [
{ place : '天河' , name : '张三' , time : '2009/07/15 10:30:20' } ,
{ place : '越秀' , name : '李四' , time : '2009/07/13 10:30:20' } ,
{ place : '黄村' , name : '王五' , time : '2009/07/12 10:30:20' }
];
// 在这里实现下方调用的方法
// 注意调用方式,是实现数组方法,不是方法函数
traces.sortBy('time');
traces;
// 此时应为按 time 字段从小到大排序的如下结构
// [
// { place : '黄村' , name : '王五' , time : '2009/07/12 10:30:20' } ,
// { place : '越秀' , name : '李四' , time : '2009/07/13 10:30:20' } ,
// { place : '天河' , name : '张三' , time : '2009/07/15 10:30:20' }
// ]
let a = 1;
let o = {
a : 2 ,
b : ()=> {
console.log(this.a);
return function(){
console.log(this.a);
}
}
}
o.b(); // 的输出 ?
o.b = o.b();
o.b(); // 的输出 ?
let c = o.b;
let k = {
a : 10
}
// 如何让 c() 输出 10;
// easy
function foo(){
this.foo && this.foo = 'bar';
};
console.log( foo() , foo );
// normal
var foo = function (){
console.log(foo);
this.foo || ( this.foo = 'bar' );
console.log(this.foo);
}();
// hard
var foo = function foo(){
console.log(foo);
this.foo || ( this.foo = 'bar' );
console.log( this.foo );
}();
console.log(foo);
// 请写出所有 console.log 的输出
// [1] your code here...
var arr = [1,2];
console.log('i am a string' == arr);
// 1. 上一行的输出是什么?
// 2. 如何使上一行代码返回 true; 请把代码写在 [1] 处
// [2] your code here...
var obj = {a: 1};
var result = obj * 10;
console.log(result);
// 1. 上一行的输出是什么?
// 2. 如何使result的值变成100; 请把代码写在 [2] 处
var a = 1;
function foo(call){
"use strict";
function bass() {
console.log(a);
}
var a = 2;
function fuzz(){
console.log(this.a);
}
return {
bass: bass ,
fuzz: fuzz ,
call: call
}
function a(){};
}
function call() {
console.log(a);
}
var o = foo(call);
o.a = 3;
// 下面三个调用的输出什么 ?
o.bass();
o.fuzz();
o.call();
var fuzz = o.fuzz;
fuzz(); // 的输出 ?
var cb = o.call;
cb(); // 的输出 ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment