Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array prototype conflict #112

Open
karianpour opened this issue Dec 19, 2017 · 0 comments
Open

Array prototype conflict #112

karianpour opened this issue Dec 19, 2017 · 0 comments

Comments

@karianpour
Copy link

karianpour commented Dec 19, 2017

The function added to Array prototype cause conflict with "for( var in ) " statement. So please change the way this function is working, my suggestion is

remove these functions

Array.prototype.toNumber
Array.prototype.dtp_toDate

and add the following

function dtp_toDate(thisarray, type) {
	var splitter = '-';
	if (/invalid/i.test(new Date('1991-9-12')))
		splitter = '/';
	
	var date = thisarray.join(splitter);
	if (thisarray.length == 5)
		date = thisarray.slice(0,3).join(splitter) +' '+ thisarray.slice(3,5).join(':')
	if (!type) return date;
	date = new Date(date);
	if (type == 'unix')
		return date.getTime();
	return date;
};

function Array2Number(thisarray) {
	return thisarray.map(function(item) {return Number(item);});
};

of course the call to the function should be changed as well

return [this.getFullYear(), this.getMonth() + 1, this.getDate()].dtp_toDate();
=>
return dtp_toDate([this.getFullYear(), this.getMonth() + 1, this.getDate()]);

Actually adding this method to prototype does not make sense as the function is not working for any array rather only array with 3 elements (Y M D).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant