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

У Number и Boolean нет this #5

Closed
ghost opened this issue Sep 30, 2012 · 3 comments
Closed

У Number и Boolean нет this #5

ghost opened this issue Sep 30, 2012 · 3 comments

Comments

@ghost
Copy link

ghost commented Sep 30, 2012

var test = function(type){
    print(type..':');
    return this;  
}

Object.test = test;
Array.test = test;
String.test = test; 
Number.test = test;
Boolean.test = test;

print({a = 1, b = 2, c = 3}.test('object'));
print([1, 2, 3].test('array'));
print('ABC'.test('string'));
print((123).test('number'));
print(true.test('boolean'));

Возвращает

object:
{"a":1,"b":2,"c":3}
array:
[1,2,3]
string:
ABC
number:
null
boolean:
null
@unitpoint
Copy link
Owner

Это примитивные типы, ну в целом согласен, было бы неплохо иметь this и для них, исправил. По коду достаточно перегрузить test только в Object.

@unitpoint
Copy link
Owner

Круто, что ты сам уже так глубоко капнул!

@ghost
Copy link
Author

ghost commented Oct 1, 2012

Мне очень-очень нравится язык. Надеюсь, что ты не забросишь это дело.

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