Skip to content

Commit 3212453

Browse files
committed
These are what I learned in 2018-01-08.
1 parent 9153de3 commit 3212453

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ This repo has a tool that help you to manage and write down what you learned in
1313
| Table of Contents | :point_down: |
1414
| -------- | -------- |
1515
| :new: **Top 5 recent learning** | |
16+
| [Debug js code using console.trace](javascript/Debug-js-code-using-console.trace.md) [javascript] | 2018-01-07 |
17+
| [Define property of an object in hacking way](javascript/Define-property-of-an-object-in-hacking-way.md) [javascript] | 2018-01-07 |
1618
| [Sleeping connections in MySQL](mysql/Sleeping-connections-in-MySQL.md) [mysql] | 2018-01-04 |
1719
| [Create cross-platform downloading app URL](http/Create-crossplatform-downloading-app-URL.md) [http] | 2018-01-03 |
1820
| [HSTS rule in browser](web/HSTS-rule-in-browser.md) [web] | 2018-01-03 |
19-
| [Using web proxy to bypass firewalls](web/Using-web-proxy-to-bypass-firewalls.md) [web] | 2017-12-07 |
20-
| [Fastly conflict detector script](git/Fastly-conflict-detector-script.md) [git] | 2017-11-27 |
2121
| :books: **bash** [ 1 articles ] | |
2222
| [Simple HTTP server function helper](bash/simple-http-server-function-helper.md) | 2017-10-05 |
2323
| :books: **chrome-dev** [ 1 articles ] | |
@@ -42,9 +42,11 @@ This repo has a tool that help you to manage and write down what you learned in
4242
| [Create cross-platform downloading app URL](http/Create-crossplatform-downloading-app-URL.md) | 2018-01-03 |
4343
| :books: **java** [ 1 articles ] | |
4444
| [Runing old java applets on brower](java/Runing-old-java-applets-on-brower.md) | 2017-08-06 |
45-
| :books: **javascript** [ 2 articles ] | |
45+
| :books: **javascript** [ 4 articles ] | |
4646
| [Eval function and with block](javascript/Eval-function-and-with-block.md) | 2017-08-10 |
4747
| [Scope and Closure](javascript/Scope-and-Closure.md) | 2017-08-10 |
48+
| [Debug js code using console.trace](javascript/Debug-js-code-using-console.trace.md) | 2018-01-07 |
49+
| [Define property of an object in hacking way](javascript/Define-property-of-an-object-in-hacking-way.md) | 2018-01-07 |
4850
| :books: **linux** [ 3 articles ] | |
4951
| [Remap Capslock to Control key](linux/remap-capslock-to-control-key.md) | 2017-08-08 |
5052
| [Send ENTER key to kernel](linux/Send-ENTER-key-to-kernel.md) | 2017-09-27 |
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- Date : 2018-01-07
2+
- Tags : #javascript #debug
3+
4+
## Debug js code using console.trace
5+
6+
Browsers provide an useful function help you debug easier than using simple `console.log` function.
7+
8+
That is `console.trace`, which prints a stack trace to called function.
9+
10+
Example :
11+
12+
```js
13+
function foo() {
14+
var a = 1;
15+
bar(a);
16+
}
17+
function bar(x) {
18+
console.log(x);
19+
console.trace();
20+
}
21+
22+
foo();
23+
```
24+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
- Date : 2018-01-07
2+
- Tags : #javascript
3+
4+
## Define property of an object in hacking way
5+
6+
Sometimes, we want to define a property of an advanced object (has setter and getter function).
7+
8+
Now, we could use this helper function `Object.defineProperty` to define property of an object in a cool way.
9+
10+
Example :
11+
12+
```js
13+
const foo = {};
14+
15+
Object.defineProperty(a, 'bar', {
16+
value: 'hogehoge',
17+
writable: false,
18+
});
19+
20+
console.log(foo.bar); // 'hogehoge'
21+
foo.bar = 'foo bar'; // throw an error in strict mode
22+
console.log(foo.bar); // still be 'hogehoge'
23+
```
24+
25+
Modifying setter, getter function
26+
27+
```js
28+
// Get callstack which function is getting or setting cookie value
29+
Object.defineProperty(document, 'cookie', {
30+
get: function() {
31+
console.log('get !');
32+
console.trace();
33+
},
34+
set: function(val) {
35+
console.log('set = ', val);
36+
console.trace();
37+
},
38+
});
39+
```
40+

0 commit comments

Comments
 (0)