Skip to content

Instantly share code, notes, and snippets.

@koyta
Created May 25, 2017 10:51
Show Gist options
  • Save koyta/e492acea28f491f71d62506b1d44ec8f to your computer and use it in GitHub Desktop.
Save koyta/e492acea28f491f71d62506b1d44ec8f to your computer and use it in GitHub Desktop.
Функциональное наследование

Функциональное наследование

Только на функциях, без использования специального синтаксиса.

const mammalia = ( spec ) =>
{
	const self = {
		'class': 'Mammalia',
		getAge()
		{
			return spec.age;
		},
	};
	
	return self;
}

const human = ( spec ) =>
{
	const self = mammalia( spec );
	
	self.sayName = () =>
	{
		console.log( 'My name is ' + spec.name );
	};
	
	return self;
}

const bob = human( {name: 'Bob', age: 20} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment