// 定义类
class Point() {
constructor(x, y) {
this.x = x;
this.y = y;
}
toString() {
return '(' + this.x + ', ' + this.y + ')';
}
}
var point = new Point(2, 3);
point.toString(); //(2, 3)
Class ColorPoint extends Point {
constructor(x, y, color) {
super(x, y); //等同于super.constructor(x, y)
this.color = color;
}
toString() {
return this.color + '' + super();
}
}
//profile.js
export var firstName = "Pandora";
export var lastName = "G.Dragon";
export var year = 1973;
//export还有下面这种写法,两者是等价的
var firstName = "Pandora";
var lastName = "G.Dragon";
var year = 1973;
export({firstName, lastName, year});
import {firstName, lastName, year} from './profile';
function setHeader(element) {
element.textContent = firstName + '' + lastName;
}
import {someMethod, another as newName} from './exporter';
// circle.js
// 方法-1: 返回圆的面积
export function area(radius) {
return Math.PI * radius * radius;
}
// 方法-2: 返回圆的周长
export function circumference(radius) {
return 2 * Mathi.PI * radius;
}
// mian.js
import {area, circumference} from 'circle';
console.log("圆面积: " + area(4));
console.log("圆周长: " + circumference(14));
// main.js
module circle from 'circle';
console.log("圆面积: " + circle.area(4));
console.log("圆周长: " + circle.circumference(14));
// export-default.js
export default function foo() { // foo()就是这个模块的默认方法
console.log('foo');
}
// import-default.js import customName from './export-default'; customName(); //'foo'
export default 42;
//circleplus.js
export * from 'circle'; // "export *"表示输出circle模块的所有属性和方法
export var e = 2.71828;
export default function(x) {
return Math.exp( x );
}
export {area as circleArea } from 'circle';
//main.js module math from 'circleplus'; import exp from "circleplus"; // "import exp"表示将circleplus模块的默认方法加载为exp方法。 console.log( exp(math.pi) );
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有