function foo(height, color)
{
var height = height || 50;
var color = color || 'red';
//...
}
foo(0, "", "")
function foo(height = 50, color = 'red')
{
// ...
}
var name = 'Your name is ' + first + ' ' + last + '.'
var name = `Your name is ${first} ${last}.`
var roadPoem = 'Then took the other, as just as fair,\n\t' + 'And having perhaps the better claim\n\t' + 'Because it was grassy and wanted wear,\n\t' + 'Though as for that the passing there\n\t' + 'Had worn them really about the same,\n\t'
var roadPoem = `Then took the other, as just as fair, And having perhaps the better claim Because it was grassy and wanted wear, Though as for that the passing there Had worn them really about the same,`
var data = $('body').data(); // data有house和mouse属性
var house = data.house;
var mouse = data.mouse;
var { house, mouse} = $('body').data()
var [col1, col2] = $('.column');
var bar = 'bar';
var foo = function ()
{
// ...
}
var baz = {
bar: bar,
foo: foo
};
var bar = 'bar';
var foo = function ()
{
// ...
}
var baz = { bar, foo };
function foo()
{
console.log(this.id);
}
var id = 1;
foo(); // 输出1
foo.call({ id: 2 }); // 输出2
var foo = () => {
console.log(this.id);
}
var id = 1;
foo(); // 输出1
foo.call({ id: 2 }); // 输出1
setTimeout(function()
{
console.log('Hello'); // 1秒后输出"Hello"
setTimeout(function()
{
console.log('Fundebug'); // 2秒后输出"Fundebug"
}, 1000);
}, 1000);
var wait1000 = new Promise(function(resolve, reject)
{
setTimeout(resolve, 1000);
});
wait1000
.then(function()
{
console.log("Hello"); // 1秒后输出"Hello"
return wait1000;
})
.then(function()
{
console.log("Fundebug"); // 2秒后输出"Fundebug"
});
{
var a = 10;
}
console.log(a); // 输出10
{
let a = 10;
}
console.log(a); // 报错“ReferenceError: a is not defined”
function Point(x, y)
{
this.x = x;
this.y = y;
this.add = function()
{
return this.x + this.y;
};
}
var p = new Point(1, 2);
console.log(p.add()); // 输出3
class Point
{
constructor(x, y)
{
this.x = x;
this.y = y;
}
add()
{
return this.x + this.y;
}
}
var p = new Point(1, 2);
console.log(p.add()); // 输出3
module.exports = {
port: 3000,
getAccounts: function() {
...
}
}
var service = require('module.js')
console.log(service.port) // 输出3000
export var port = 3000
export function getAccounts(url) {
...
}
import {port, getAccounts} from 'module'
console.log(port) // 输出3000
import * as service from 'module' console.log(service.port) // 3000
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有