Skip to content

Instantly share code, notes, and snippets.

@Yang03
Last active October 10, 2017 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yang03/01f28ec95593df3cadc17aedb1b808f6 to your computer and use it in GitHub Desktop.
Save Yang03/01f28ec95593df3cadc17aedb1b808f6 to your computer and use it in GitHub Desktop.
Object.defineProperty
var foo = {}
Object.defineProperty(foo, 'name', {
configurable: true, //是否可以delete foo.delete
enumerable: true, // 是否for in可以返回属性
writable:true, //是否可以重新赋值
value: 'kobe'
})
var descriptor = Object.getOwnPropertyDescriptor(foo, 'name')
console.log(descriptor.value)
console.log(foo.name) // kobe
@Yang03
Copy link
Author

Yang03 commented Oct 10, 2017

function sum(list) {
  if (list.length === 0) {
    return 0;
  } else {
    const [atom, ...remainder] = list;
    const left = atom;
    const right = sum(remainder);

    return left + right;
  }
}

sum([42, 3, -1])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment