1 2 3 4 5 | export function add(a, b) { return a + b; } export const PI = 3.14; |
1 2 3 4 | import { add, PI } from './math.js' ; console.log(add(1, 2)); // 输出3 console.log(PI); // 输出3.14 |
1 2 3 4 5 6 7 8 9 10 | function Parent() { this .name = 'parent' ; } Parent.prototype.sayHello = function () { console.log( 'Hello, ' + this .name); } const parent = new Parent(); parent.sayHello(); // 输出 Hello, parent |
1 2 3 4 5 6 7 8 | function Child() { this .name = 'child' ; } Child.prototype = Object.create(Parent.prototype); const child = new Child(); child.sayHello(); // 输出 Hello, child |
本文为翻滚的胖子原创文章,转载无需和我联系,但请注明来自猿教程iskeys.com