Skip to content

Instantly share code, notes, and snippets.

const age = 2;
function example(str) {
eval(str);
console.log(age);
}
example('const age=3;'); //output:2
example("'use strict'; var age=6;"); //output:2
example('var age=4;'); // output: 4
const obj = {
a: 1,
b: 2,
c: 3,
};
with (obj) {
d = 4;
}
console.log(obj) // output: {a: 1, b: 2, c: 3}
const obj = {
a: 1,
b: 2,
c: 3,
};
with (obj) {
a = 3;
b = 4;
c = 5;
function Person(name, age) {
this.name = name;
this.age = age;
this.getName = function() {
return this.name;
}
}
Person.prototype.getAge = function() {
return this.age;
var age = 2;
const person = {
age: 1,
doSomething(name) {
console.log(this === person);
console.log(this.age);
console.log(name);
},
};
const extractFn = person.doSomething;
var age = 2;
const person = {
age: 1,
doSomething() {
console.log(this === person); // output: true
console.log(this.age); // output: 1
},
};
person.doSomething();
@obetame
obetame / webAuthnHelper.js
Created March 25, 2019 02:07
WebAuthn helper function in brower
function str2ab(str) {
const buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
const bufView = new Uint16Array(buf);
for (let i=0, strLen=str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
function ab2str(buf) {
return String.fromCharCode.apply(null, new Uint8Array(buf));
@obetame
obetame / css
Created March 29, 2018 09:12
grid 布局
html, body {
height: 100%;
margin: 0;
}
.app {
height: 100%;
display: grid;
grid-template-rows: 45px 1fr;
grid-template-columns: 200px 1fr;