yukar - Chrome Extension JavaScript Code Editor, js 代码编辑预览 chrome 插件

2018-05-25 16:47:30 +08:00
 coraline

可以在这里安装:

https://chrome.google.com/webstore/detail/yukar/ilbmpnheigbnilnbknenakbkkdmaemlp

源码在这里:

https://github.com/LoeiFy/yukar

外什么要做这个插件

功能介绍

Async

;(async () => {
  const a = await 'Async Await'
  console.log(a)
})()
// Async Await

Class Properties

class A {
  s = 'Class Properties'
	test() {
    console.log(this.s)
  }
}

(new A()).test()
// Class Properties

Object Rest Spread

const s = [1,2]
const b = [3, ...s]
console.log(b)
// 3,1,2

Decorators

function log(target, name, descriptor) {
  const original = descriptor.value
  if (typeof original === 'function') {
    descriptor.value = function(...args) {
      console.log(`Arguments: ${args}`)
      try {
        const result = original.apply(this, args)
        console.log(`Result: ${result}`)
        return result
      } catch (e) {
        console.log(`Error: ${e}`)
        throw e
      }
    }
  }
  return descriptor
}

class Example {
    @log
    sum(a, b) {
        return a + b
    }
}

const e = new Example()
e.sum(1, 2)
// Arguments: 1,2
// Result: 3

React JSX

<script crossorigin src="//unpkg.com/moment@2.14.1/min/moment.min.js"></script>
<script crossorigin src="//unpkg.com/react@16.3.2/umd/react.production.min.js"></script>
<script crossorigin src="//unpkg.com/react-dom@16.3.2/umd/react-dom.production.min.js"></script>
<script crossorigin src="//unpkg.com/antd@3.5.2/dist/antd-with-locales.min.js"></script>
<script>window['react'] = window.React;window['reactDom'] = window.ReactDOM</script>
<link rel="stylesheet" href="//unpkg.com/antd@3.5.2/dist/antd.min.css" />

<div id="root"></div>
import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import { Modal, Button } from 'antd';

function success() {
  const modal = Modal.success({
    title: 'This is a notification message',
    content: 'This modal will be destroyed after 1 second',
  });
  setTimeout(() => modal.destroy(), 1000);
}


ReactDOM.render(
  <Button onClick={success}>Success</Button>,
  document.getElementById('root')
);

Vue JSX

<script src="https://unpkg.com/vue"></script>
<div id="app"></div>
new Vue({
  el: '#app',
  data: {
    msg: 'Support vue jsx'
  },
  methods: {
    hello () {
      alert('This is the message.')
    }
  },
  render(h) {
    return (
      <span class={{ 'my-class': true }} on-click={ this.hello }>
        { this.msg }
      </span>
    )
  }
})

预览图片

1708 次点击
所在节点    分享创造
3 条回复
DearMark
2018-05-25 16:55:57 +08:00
还不错,简单直接
songz
2018-05-25 16:56:44 +08:00
跑个 alert(1)会闪
coraline
2018-05-26 16:03:40 +08:00
@songz

已经修复这个问题,不过要过一段时间才发到 chrome web store

现在的话不用原生的弹窗方法都没问题的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/457771

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX