File "base-model.js"

Full Path: /home/warrior1/public_html/wp-content/plugins/elementor/app/modules/kit-library/assets/js/models/base-model.js
File size: 627 bytes
MIME-type: text/plain
Charset: utf-8

export default class BaseModel {
	/**
	 * Clone to object to avoid changing the reference.
	 *
	 * @return {BaseModel} cloned model
	 */
	clone() {
		const instance = new this.constructor();

		Object.keys( this ).forEach( ( key ) => {
			instance[ key ] = this[ key ];
		} );

		return instance;
	}

	/**
	 * Using init and not the default constructor because there is a problem to fill the instance
	 * dynamically in the constructor.
	 *
	 * @param {*} data
	 * @return {BaseModel} model
	 */
	init( data = {} ) {
		Object.entries( data ).forEach( ( [ key, value ] ) => {
			this[ key ] = value;
		} );

		return this;
	}
}