STORE = {
item : function() {
}
};
STORE.item.prototype.add = function() { alert('test 123'); };
STORE.item.add();
Run Code Online (Sandbox Code Playgroud)
我一直想弄清楚这有什么问题.为什么这不起作用?但是,当我使用以下内容时它可以工作:
STORE.item.prototype.add();
Run Code Online (Sandbox Code Playgroud) 我明白有一个星号*是指针,有两个**是什么意思?
我从文档中偶然发现了这个:
- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary **)errorInfo
Run Code Online (Sandbox Code Playgroud) 假设我们有一个第一个Object'Controller',它初始化另一个名为'Tasks'的对象,同时传递'self'以供参考.Tasks对象现在可以与超级'Controller'对象进行通信并发送消息.这对于对象之间的通信是否正确?这通常是怎么做的?我刚刚开始真正学习编程,所以我想知道这是否正常.到目前为止,我依靠代表和通知.这是好习惯吗?
例:
// Controller Object
task = [[Task alloc] initWithController: self];
- (void) runMethod: (NSString *) incoming {
NSLog(@"%@", incoming);
}
// Task Object
- (id) initWithController: (Controller *) ctrlr {
controllerPointer = ctrlr;
[controllerPointer runMethod:@"hello"];
return self
}
// All this should print out "hello"
Run Code Online (Sandbox Code Playgroud)
还有其他方式进行通信,在对象之间进行交互吗?
我想确定区域被赋予任意数字的位置.
zones = [0, 150, 300, 400, 600, 800]
function checkZone(mouseX) {
// if mouseX is 321, it should be index 2 of zones array
}
Run Code Online (Sandbox Code Playgroud)