作用域 當前類 同一package 子孫類 其他package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不寫時默認為 friendly
作用域 當前類 同一package 子孫類 其他package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不寫時默認為 friendly
1. What is the difference between undefined and not defined in JavaScript?
> var x; // declaring x
> console.log(x); //output: undefined
=====================================================
> console.log(y); // Output: ReferenceError: y is not defined
2. What will be the output of the code below?
var y = 1;
if (function f(){}) {
y += typeof f;
}
console.log(y);
The output would be 1undefined.
=====================================================
var k = 1;
if (1) {
eval(function foo(){});
k += typeof foo;
}
console.log(k);
The code above will also output 1undefined.
=====================================================
var k = 1;
if (1) {
function foo(){};
k += typeof foo;
}
console.log(k); // output 1function
3.What is the drawback of creating true private methods in JavaScript?
One of the drawbacks of creating true private methods in JavaScript is that they are very memory-inefficient, as a new copy of the method would be created for each instance.
=====================================================
var Employee = function (name, company, salary) {
this.name = name || ""; //Public attribute default value is null
this.company = company || ""; //Public attribute default value is null
this.salary = salary || 5000; //Public attribute default value is null
// Private method
var increaseSalary = function () {
this.salary = this.salary + 1000;
};
// Public method
this.dispalyIncreasedSalary = function() {
increaseSlary();
console.log(this.salary);
};
};
// Create Employee class object
var emp1 = new Employee("John","Pluto",3000);
// Create Employee class object
var emp2 = new Employee("Merry","Pluto",2000);
// Create Employee class object
var emp3 = new Employee("Ren","Pluto",2500);
emp1.dispalyIncreasedSalary()
=====================================================
error: Uncaught ReferenceError: increaseSlary is not defined
=====================================================
Here each instance variable emp1, emp2, emp3 has its own copy of the increaseSalary private method.
So, as a recommendation, don’t use private methods unless it’s necessary.
4. What is a “closure” in JavaScript? Provide an example
A closure is a function defined inside another function (called the parent function), and has access to variables that are declared and defined in the parent function scope.
The closure has access to variables in three scopes:
Variables declared in their own scope
Variables declared in a parent function scope
Variables declared in the global namespace
=====================================================
var globalVar = "abc";
// Parent self invoking function
(function outerFunction (outerArg) { // begin of scope outerFunction
// Variable declared in outerFunction function scope
var outerFuncVar = 'x';
// Closure self-invoking function
(function innerFunction (innerArg) { // begin of scope innerFunction
// variable declared in innerFunction function scope
var innerFuncVar = "y";
console.log(
"outerArg = " + outerArg + "\n" +
"outerFuncVar = " + outerFuncVar + "\n" +
"innerArg = " + innerArg + "\n" +
"innerFuncVar = " + innerFuncVar + "\n" +
"globalVar = " + globalVar);
})(5)// end of scope innerFunction)(5); // Pass 5 as parameter
})(7)// end of scope outerFunction )(7); // Pass 7 as parameter
=====================================================
outerArg = 7
outerFuncVar = x
innerArg = 5
innerFuncVar = y
globalVar = abc
=====================================================
5. Write a mul function which will produce the following outputs when invoked:
=====================================================
function mul (x) {
return function (y) { // anonymous function
return function (z) { // anonymous function
console.log("x:"+x+",y:"+y+",z:"+z);
return x * y * z;
};
};
}
console.log(mul(2)(3)(4)); // output : 24
console.log(mul(4)(3)(4)); // output : 48
=====================================================
x:2,y:3,z:4
24
x:4,y:3,z:4
48
=====================================================
6. How to empty an array in JavaScript?
var arrayList = ['a','b','c','d','e','f'];
=====================================================
Method 1
var arrayList = ['a','b','c','d','e','f']; // Created array
var anotherArrayList = arrayList; // Referenced arrayList by another variable
arrayList = []; // Empty the array
console.log(anotherArrayList); // Output ['a','b','c','d','e','f']
Above code will set the variable arrayList to a new empty array. This is recommended if you don't have references to the original array arrayList anywhere else, because it will actually create a new, empty array. You should be careful with this method of emptying the array, because if you have referenced this array from another variable, then the original reference array will remain unchanged.
=====================================================
Method 2
var arrayList = ['a','b','c','d','e','f']; // Created array
var anotherArrayList = arrayList; // Referenced arrayList by another variable
arrayList.length = 0; // Empty the array by setting length to 0
console.log(anotherArrayList); // Output []
The code above will clear the existing array by setting its length to 0. This way of emptying the array also updates all the reference variables that point to the original array. Therefore, this method is useful when you want to update all reference variables pointing to arrayList.
=====================================================
Method 3
var arrayList = ['a','b','c','d','e','f']; // Created array
var anotherArrayList = arrayList; // Referenced arrayList by another variable
arrayList.splice(0, arrayList.length); // Empty the array by setting length to 0
console.log(anotherArrayList); // Output []
The implementation above will also work perfectly. This way of emptying the array will also update all the references to the original array.
=====================================================
Method 4
while(arrayList.length){
arrayList.pop();
}
The implementation above can also empty arrays, but it is usually not recommended to use this method often.
=====================================================
7.How do you check if an object is an array or not?
The best way to find out whether or not an object is an instance of a particular class is to use the toString method from Object.prototype:
var arrayList = [1,2,3];
Array.isArray(arrayList);
8.What will be the output of the following code?
=====================================================
var output = (function(x){
delete x;
return x;
})(0);
console.log(output);
The output would be 0. The delete operator is used to delete properties from an object. Here x is not an object but a local variable. delete operators don't affect local variables.
Reference:
https://www.codementor.io/@nihantanu/21-essential-javascript-tech-interview-practice-questions-answers-du107p62z
依 Linux 為例,利用 task struct 是 linux kernel 用來描述 process thread 結構 schedule.h 裡面
Process ( 程序、進程 )
Process 意旨已經執行並且 load 到記憶體中的 Program ,程序中的每一行程式碼隨時都有可能被CPU執行。
每一個 Process 是互相獨立的
Process 是 Thread 的容器
在多功作業系統(Multitasking Operating System)中,可以同時執行數個Process ,然而一個 CPU 一次只能執行一個 Process (因此才有現在的多核處理器),而 Process 的運行量總量不會少於 CPU 的總量,又Process 會佔用記憶體,因此如何排程(Scheduling,恐龍本第五章) 、如何有效管理記憶體(恐龍本第八章)則是 OS 所關注的事
Thread (執行緒、線程 )
同一個 Process 中會有很多個 Thread ,每一個 Thread 負責某一項功能。
同一個 Process 底下的 Thread 共享資源,如 記憶體、變數等,不同的Process 則否。
在多執行緒中(Multithreading),兩個執行緒若同時存取或改變全域變數(Global Variable),則可能發生同步(Synchronization,恐龍本第六章)問題。若執行緒之間互搶資源,則可能產生死結(Deadlock,恐龍本第七章),同樣的,如何避免或預防上述兩種情況的發生,依然是 OS 所關注並改善的。
刪除每行前 3 個字元
:%s/^.\{3\}//
刪除每行後 3 個字元
:%s/.\{3\}$//
刪除偶數行
:%s/\(^.*$\)\n^.*$/\1/g
刪除奇數行
:%s/^.*$\n\(^.*$\)/\1/g
鏈結串列的抽象資料結構 (ADT)
Linked list (連結串列) 是一種常見的資料結構,其使用 node (節點)來記錄、表示、儲存資料(data),並利用每個 node 中的 pointer 指向下一個 node,藉此將多個 node 串連起來,形成 Linked list,並以 NULL 來代表 Linked list 的終點,見圖一(a)。
Node2 = Node1->Next
刪除節點在 middle
刪除節點在 tailReference:
https://alrightchiu.github.io/SecondRound/linked-list-introjian-jie.html
Android筆記-Linux Kernel Ftrace (Function Trace)解析
Process Synchronization(同步)--上 (race condition, critical section)
Process Synchronization(同步)--中 (critical section problem的解決方法)
Process Synchronization(同步)--下 (常看到的經典問題)
Deadlocks(死結)--上 (形成deadlock,必須同時滿足4個條件)
【n8n免費本地端部署】Windows版|程式安裝x指令大補帖 【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能