本文整理汇总了TypeScript中es6-shim.Object类的典型用法代码示例。如果您正苦于以下问题:TypeScript Object类的具体用法?TypeScript Object怎么用?TypeScript Object使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Object类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: switch
const copyFileAndShowSummary = (state: AppState = initialState, action: any) => {
switch (action.type) {
case types.COPY_FILE_CONTENTS:
let copy_action: CopyFileContents = action;
return ES6.Object.assign({}, state, {
fileNameOrErrorMessage: copy_action.fileName,
text: copy_action.contents
})
case types.REJECT_FILE:
let reject_action: RejectFile = action;
return ES6.Object.assign({}, state, {
fileNameOrErrorMessage: reject_action.errorMessage
})
case types.SHOW_TEXT_SUMMARY:
let summarize_action: ShowTextSummary = action;
let line_number = summarize_action.text.split('\n').length;
if (summarize_action.text === "") {
line_number = 0
}
let char_and_space_count = summarize_action.text.length;
// convert [\r\n\t\s]+ to spaces
let text = summarize_action.text.replace(/[\r\n\t\s]+/g, " ").trim();
let word_count = text.split(" ").length;
if (text === "") {
word_count = 0
}
// remove spaces
text = text.replace(/ /g, "");
let char_count = text.length;
return ES6.Object.assign({}, state, {
text: summarize_action.text,
summary: {
character_count: char_count,
character_and_space_count: char_and_space_count,
word_count: word_count,
line_number: line_number
}
})
default:
return state
}
}
示例2:
const changeColor = (state, action) =>
ES6.Object.assign({}, state, { color: action.color });
示例3:
export const changeShape = (state, action) => {
var shape = ES6.Object.assign({}, state.shapes.filter(x => x.id === action.id)[0],
{ top: action.top, left: action.left });
return ES6.Object.assign({}, state, { shapes: [...state.shapes.filter(x => x.id !== action.id), shape] });
};