Skip to content

Commit

Permalink
new
Browse files Browse the repository at this point in the history
  • Loading branch information
baichun committed Jul 4, 2019
1 parent 8dd32f9 commit 0923237
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
42 changes: 42 additions & 0 deletions src/algorithm/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//实现(5).add(3).minus(2)功能
Number.prototype.add = function(m){
return this.valueOf()+m
}

Number.prototype.minus = function(m){
return this.toString()*1-m
}

console.log((5).add(3).minus(2))

//实现add(1)(2)(3)
function add(m){
let fn = function(n){
return add(m+n)
}

fn.toString = function(){
return m
}

return fn
}
console.log(add(1)(2)(3))

//简述一下new一个对象的过程
function _new(fn,args){
let p = Object.create(fn.prototype)
let o = fn.apply(p,args)
return typeof o ==="object" ? o :p
}

function a(name){
this.name = name
}

a.prototype.sayname = function(){
console.log(this.name)
}

let dog = _new(a,["dog"])
dog.sayname()
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import {bubbleSort} from '@/algorithm/bubbleSort'
// import '@/algorithm/problem190612'
// import '@/algorithm/problem190603'
import '@/algorithm/problem190619'
// import '@/algorithm/problem190619'
import '@/algorithm/new'

0 comments on commit 0923237

Please sign in to comment.