Created
March 19, 2017 00:20
-
-
Save MiguelSavignano/d145687262abf8657df52f6c6af072f5 to your computer and use it in GitHub Desktop.
Test new features in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printArguments(target, name, descriptor) { | |
let oldFunction = descriptor.value | |
descriptor.value = function () { | |
console.log(`start ${name} with arguments`, arguments) | |
oldFunction.apply(target, arguments) | |
console.log(`end function ${name}`) | |
} | |
return descriptor | |
} | |
export default class Example { | |
// transform-async-generator-functions | |
count = 0 | |
async getPosts() { | |
const response = await fetch("https://jsonplaceholder.typicode.com/posts") | |
const posts = await response.json() | |
console.log(posts) // async function | |
} | |
// transform-object-rest-spread | |
mergeObject() { | |
const objectDefault = { a: 0, b: 2 } | |
const object = { ...objectDefault, b: 1, c: 3 } | |
console.log("objectDefault", objectDefault) // { a: 0, b: 2 } | |
console.log("object", object) // { a: 0, b: 1, c:3 } | |
} | |
// transform-decorators-legacy | |
@printArguments | |
sum(a, b){ | |
console.log(a + b) | |
} | |
// transform-class-properties | |
incrementCount = () => { | |
this.count++ | |
console.log("incrementCount", this.count) | |
} | |
} | |
// Auto Run | |
const example = new Example | |
example.getPosts() | |
example.mergeObject() | |
example.sum(1, 1) | |
example.incrementCount() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment