Skip to content

Instantly share code, notes, and snippets.

View bitfishxyz's full-sized avatar
🐥
🐔🐔🥚🥚

medium003 bitfishxyz

🐥
🐔🐔🥚🥚
View GitHub Profile
let obj = {
a: 1,
b: 2
}
Object.defineProperty(obj, 'a', {
enumerable: false
})
for (let key in obj){
console.log(key) // b
var a = [1, 2, 3]
for(let key in a){
console.log(key)
}
console.log(Object.getOwnPropertyDescriptor(a, 'length'))
let obj = {
a: 1
}
Object.defineProperty(obj, 'a', {
configurable: false
})
// will throw an error
Object.defineProperty(obj, 'a', {
enumerable: false
let obj = {
a: 1
}
Object.defineProperty(obj, 'a', {
configurable: false
})
obj.a = 3
console.log(obj.a) // 3
var p1 = {
get age(){
console.log('triggle get method')
console.log('you can do anything as you want')
return 18
},
set age(age){
console.log('triggle get method')
console.log('you can do anything as you want')
console.log(`you are trying to assign ${age} to this.age`)
<!DOCTYPE html>
<html>
<head>
<style>
input{
font-size: 233px
}
</style>
</head>
<body>
function newOperator(constructor, args) {
var new_created_obj = Object.create(constructor.prototype)
constructor.apply(new_created_obj, args)
return new_created_obj
}
function Person(name, age) {
this.name = name
}
Person.prototype.getName = function (){
class PersonClass{
constructor(name, age){
this.name = name
this.age = age
}
getName(){
return this.name
}
}
class PersonClass{
constructor(name, age){
this.name = name
this.age = age
}
getName(){
return this.name
}
}
class AdultClass extends PersonClass{
@bitfishxyz
bitfishxyz / call.js
Created February 7, 2019 11:26
Imitation of Function.prototype.call
Function.prototype.myCall = function(thisArgs) {
thisArgs.$fn = this //
let args = []
for(let i = 1; i<arguments.length; i++){
args.push(arguments[i])
}
var result = thisArgs.$fn(...args)
delete thisArgs.$fn
return result
}