當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript types.isObject函數代碼示例

本文整理匯總了TypeScript中vs/base/common/types.isObject函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript isObject函數的具體用法?TypeScript isObject怎麽用?TypeScript isObject使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了isObject函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

		Object.keys(source).forEach(key => {
			if (key in destination) {
				if (overwrite) {
					if (isObject(destination[key]) && isObject(source[key])) {
						mixin(destination[key], source[key], overwrite);
					} else {
						destination[key] = source[key];
					}
				}
			} else {
				destination[key] = source[key];
			}
		});
開發者ID:developers23,項目名稱:vscode,代碼行數:13,代碼來源:objects.ts

示例2: _cloneAndChange

function _cloneAndChange(obj: any, changer: (orig: any) => any, encounteredObjects: any[]): any {
	if (isUndefinedOrNull(obj)) {
		return obj;
	}

	const changed = changer(obj);
	if (typeof changed !== 'undefined') {
		return changed;
	}

	if (isArray(obj)) {
		const r1: any[] = [];
		for (let i1 = 0; i1 < obj.length; i1++) {
			r1.push(_cloneAndChange(obj[i1], changer, encounteredObjects));
		}
		return r1;
	}

	if (isObject(obj)) {
		if (encounteredObjects.indexOf(obj) >= 0) {
			throw new Error('Cannot clone recursive data-structure');
		}
		encounteredObjects.push(obj);
		const r2 = {};
		for (let i2 in obj) {
			if (_hasOwnProperty.call(obj, i2)) {
				(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, encounteredObjects);
			}
		}
		encounteredObjects.pop();
		return r2;
	}

	return obj;
}
開發者ID:developers23,項目名稱:vscode,代碼行數:35,代碼來源:objects.ts

示例3: _cloneAndChange

function _cloneAndChange(obj: any, changer: (orig: any) => any, seen: Set<any>): any {
	if (isUndefinedOrNull(obj)) {
		return obj;
	}

	const changed = changer(obj);
	if (typeof changed !== 'undefined') {
		return changed;
	}

	if (isArray(obj)) {
		const r1: any[] = [];
		for (const e of obj) {
			r1.push(_cloneAndChange(e, changer, seen));
		}
		return r1;
	}

	if (isObject(obj)) {
		if (seen.has(obj)) {
			throw new Error('Cannot clone recursive data-structure');
		}
		seen.add(obj);
		const r2 = {};
		for (let i2 in obj) {
			if (_hasOwnProperty.call(obj, i2)) {
				(r2 as any)[i2] = _cloneAndChange(obj[i2], changer, seen);
			}
		}
		seen.delete(obj);
		return r2;
	}

	return obj;
}
開發者ID:PKRoma,項目名稱:vscode,代碼行數:35,代碼來源:objects.ts

示例4: _flaten

	private static _flaten(obj: any, result: {[key: string]: any }, order: number = 0, prefix?: string): void {
		if (!obj) {
			return;
		}

		for(var item of Object.getOwnPropertyNames(obj)){
			const value = obj[item];
			const index = prefix ? prefix + item : item;

			if (Array.isArray(value)) {
				result[index] = safeStringify(value);

			} else if (value instanceof Date) {
				// TODO unsure why this is here and not in _getData
				result[index] = value.toISOString();

			} else if (isObject(value)) {
				if (order < 2) {
					AIAdapter._flaten(value, result, order + 1, index + '.');
				} else {
					result[index] = safeStringify(value);
				}
			} else {
				result[index] = value;
			}
		}
	}
開發者ID:Buildsoftwaresphere,項目名稱:vscode,代碼行數:27,代碼來源:aiAdapter.ts

示例5:

		Object.keys(source).forEach((key: keyof T) => {
			let destValue = destination[key];
			let sourceValue = source[key];
			if (Types.isUndefined(sourceValue)) {
				return;
			}
			if (Types.isUndefined(destValue)) {
				destination[key] = sourceValue;
			} else {
				if (overwrite) {
					if (Types.isObject(destValue) && Types.isObject(sourceValue)) {
						this.merge(destValue, sourceValue, overwrite);
					} else {
						destination[key] = sourceValue;
					}
				}
			}
		});
開發者ID:AlexxNica,項目名稱:sqlopsstudio,代碼行數:18,代碼來源:parsers.ts

示例6: mixin

export function mixin(destination: any, source: any, overwrite: boolean = true): any {
	if (!isObject(destination)) {
		return source;
	}

	if (isObject(source)) {
		Object.keys(source).forEach(key => {
			if (key in destination) {
				if (overwrite) {
					if (isObject(destination[key]) && isObject(source[key])) {
						mixin(destination[key], source[key], overwrite);
					} else {
						destination[key] = source[key];
					}
				}
			} else {
				destination[key] = source[key];
			}
		});
	}
	return destination;
}
開發者ID:developers23,項目名稱:vscode,代碼行數:22,代碼來源:objects.ts

示例7: test

	test('create', () => {
		let zeroConstructor = function () { /**/ };

		assert(types.create(zeroConstructor) instanceof zeroConstructor);
		assert(types.isObject(types.create(zeroConstructor)));

		let manyArgConstructor = function (this: any, foo, bar) {
			this.foo = foo;
			this.bar = bar;
		};

		let foo = {};
		let bar = 'foo';

		assert(types.create(manyArgConstructor) instanceof manyArgConstructor);
		assert(types.isObject(types.create(manyArgConstructor)));

		assert(types.create(manyArgConstructor, foo, bar) instanceof manyArgConstructor);
		assert(types.isObject(types.create(manyArgConstructor, foo, bar)));

		let obj = types.create(manyArgConstructor, foo, bar);
		assert.strictEqual(obj.foo, foo);
		assert.strictEqual(obj.bar, bar);
	});
開發者ID:DonJayamanne,項目名稱:vscode,代碼行數:24,代碼來源:types.test.ts


注:本文中的vs/base/common/types.isObject函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。