创建一个对象的字面方法
示例:
var obj = {};
var Point = {x : 10, y : 10}
示例:
var obj = new Object();
var obj = new Object(null);
var obj = new Object(undefined);
以obj
为原型创建新对象。
示例:
//渲染界面时候传入的对象的基本内容
const baseRenderData = {
baseDir: baseDir,
viewsDir: viewsDir,
baseImageUrl: baseImageUrl
};
function registerEJSRender(item) {
router.get(item, function (request, response, next) {
var data = Object.create(baseRenderData);
data['baseImageUrlWithUrlPath'] = baseImageUrl + item;
data['currentUrlPath'] = item;
data['isLogined'] = isLogin(request);
response.render(item.substring(1), data);
});
}
const pathList = ['/', '/a', '/a/b', '/a/b/c'];
pathList.forEach(path => {
registerEJSRender(path);
});
获取obj
对象中的所有key
,以数组形式返回。
示例:
const tasks = {
//压缩prism.js
compressPrismJS : callback => {
pump([
uglify(uglifyOption),
], callback);
},
//压缩、混淆src/public/js目录下的js文件
compressMyJS : callback => {
pump([
gulp.src('src/public/js/**/*.js'),
uglify(uglifyOption),
gulp.dest(outputJSDir)
], callback);
}
};
for(taskName in tasks) {
gulp.task(taskName, tasks[taskName]);
}
gulp.task('default', Object.keys(tasks));