Hello World from Objective-J

在看了almost.at网站之后,我找到了Cappuccino

 Cappuccino是一个很好的框架。有让我心动的UI层。很苹果。又能免去写

我决定看看这个用Objective-J的框架。

 

 

顺手译了一篇起步(意译):

原文:http://objective-j.org/learn/tutorials/objective-j-tutorial.php

 

 

Objective-J is a new programming language based on Objective-C. It is a superset of JavaScript, which means that any valid JavaScript code is also valid Objective-J code. Anyone familiar with JavaScript and object-oriented programming concepts, classical inheritance in particular, should have no difficulty learning Objective-J. Familiarity with Objective-C will be helpful, but it is not required.

Objective-J是一种新的编程语言。它基于Objective-C。它是Javascript的超集,这意味着,任何合法的Javascript代码都是合法的Objective-J代码。熟悉Javascript和OO编程概念的人-传统的继承概念-都不会在学习Objective-J的时候有困难。
熟悉Objective-C会很有帮助,但是不要求。

Objective-J has two types of objects, native JavaScript objects and Objective-J objects. Native JS objects are exactly what they sound like, the objects native to JavaScript. Objective-J objects are a special type of native object added by Objective-J. These new objects are based on classes and classical inheritance, like C++ or Java, instead of the prototypal model.

Objective-J有两种对象-原生Javascript对象和Objective-J对象。原生JS对象,名符其实的javascript的对象。Objective-J对象是一种特殊的原生对象。这些对象基于对象结构和继承,就像C++和Java一样,而不是prototypal模式的。
最简单的一个类:
 
一个类从@implementation开始,到@end结束。
方法:
 
-代表,这个方法是实例方法。
+可能代表类方法,we'll find out.
注意方法参数:
- (void)setJobTitle:(CPString)aJobTitle company:(CPString)aCompany
类型最好是声明出来,当然也不强求。

In Objective-J, method names are split across all of the arguments to a method. These are not technically named arguments. The method above is named setJobTitle:company:. This is achieved by concatenating the first part of the method with all the subsequent labels, in order.

在OJ中,方法名是分开的。这些参数实际上说,并不是命名参数。 上面这个方法的名字是 setJobTitle:company:

 

The parameters to a method must be passed in order, and all of the parameters are required. To call such a multiple parameter method, we pass our data after each label:

参数在传入时是有顺序的,并且都是要求的(没有默认参数这一说)。调用一个多参数的方法,可能是这样的:

 

[myPerson setJobTitle:"Founder" company:"280 North"];

As you can see, each colon is followed by the input that will be mapped to that parameter name. That sequence of label, colon, input is repeated for each parameter.

你可以看到,每个冒号后面都有一个输入参数,他们会被映射到各个参数名称。

You may be wondering why it matters what the actual name of the method is. One pattern you'll find in Objective-J and Cappuccino is the idea of passing a method as an argument to another method. This is used commonly in delegation and in the event system. Since methods aren't first class objects in the same way as JavaScript, we use a special notation to refer to them, @selector. If I wanted to pass the previous method as an argument to another method, I would use the following code:

你可能想知道为什么一个方法的真实名字很重要。OJ里,回调的手法很普遍,可能会有很多这样的代码:
[fooObject setCallbackSelector:@selector(setJobTitle:company:)];
如何使用一个对象。
This block of code creates a new Person object, and sets the name:
这段代码创建了一个Person对象,设置了name:
var myPerson = [[Person alloc] init];
[myPerson setName:"John"];
blahblah.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值