jsface
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -1,2 +0,2 @@ | ||
v2.1.1 TBD | ||
v2.x.0 TBD | ||
---------------------------------------------------------------- | ||
@@ -6,2 +6,9 @@ * Add overloading plugin: support method overloading, type | ||
v2.1.1 Apr 25, 2012 | ||
---------------------------------------------------------------- | ||
* Introduce main() | ||
* Fix bug in 2.1.0 causing all static properties got written to | ||
class prototype | ||
* Minor toString alias optimization | ||
v2.1.0 Mar 15, 2012 | ||
@@ -8,0 +15,0 @@ ---------------------------------------------------------------- |
/* | ||
* JSFace Object Oriented Programming Library | ||
* https://github.com/tannhu/jsface | ||
* https://github.com/tnhu/jsface | ||
* | ||
* Copyright (c) 2009-2012 Tan Nhu | ||
* Licensed under MIT license (https://github.com/tannhu/jsface/blob/master/MIT-LICENSE.txt) | ||
* Version: 2.1.0 | ||
* Licensed under MIT license (https://github.com/tnhu/jsface/blob/master/LICENSE.txt) | ||
*/ | ||
(function(context, OBJECT, NUMBER, LENGTH, undefined, oldClass, jsface) { | ||
(function(context, OBJECT, NUMBER, LENGTH, toString, undefined, oldClass, jsface) { | ||
"use strict"; | ||
@@ -37,3 +36,3 @@ | ||
function isString(obj) { | ||
return Object.prototype.toString.apply(obj) === "[object String]"; | ||
return toString.apply(obj) === "[object String]"; | ||
} | ||
@@ -88,3 +87,3 @@ | ||
var clazz, constructor, singleton, statics, key, bindTo, len, i = 0, p, | ||
ignoredKeys = { constructor: 1, $singleton: 1, $statics: 1, prototype: 1, $super: 1, $superp: 1 }, | ||
ignoredKeys = { constructor: 1, $singleton: 1, $statics: 1, prototype: 1, $super: 1, $superp: 1, main: 1 }, | ||
overload = Class.overload, | ||
@@ -118,4 +117,8 @@ plugins = Class.plugins; | ||
for (key in api) bindTo[key] = api[key]; | ||
for (key in statics) { clazz[key] = bindTo[key] = statics[key]; } | ||
for (key in api) { | ||
if ( !ignoredKeys[key]) bindTo[key] = api[key]; | ||
} | ||
for (key in statics) { | ||
clazz[key] = bindTo[key] = statics[key]; | ||
} | ||
@@ -129,2 +132,3 @@ if ( !singleton) { | ||
for (key in plugins) { plugins[key](clazz, parent, api); } // pass control to plugins | ||
if (isFunction(api.main)) { api.main.call(clazz, clazz); } // execute main() | ||
@@ -156,2 +160,2 @@ return clazz; | ||
} | ||
})(this, "object", "number", "length"); | ||
})(this, "object", "number", "length", Object.prototype.toString); |
/* | ||
* JSFace Object Oriented Programming Library - Plug and Play pointcut plugin | ||
* https://github.com/tannhu/jsface | ||
* https://github.com/tnhu/jsface | ||
* | ||
* Copyright (c) 2009-2012 Tan Nhu | ||
* Licensed under MIT license (https://github.com/tannhu/jsface/blob/master/MIT-LICENSE.txt). | ||
* Version: 2.1.0 | ||
* Licensed under MIT license (https://github.com/tnhu/jsface/blob/master/LICENSE.txt). | ||
*/ | ||
@@ -9,0 +8,0 @@ (function(context) { |
/* | ||
* JSFace Object Oriented Programming Library - Ready plugin | ||
* https://github.com/tannhu/jsface | ||
* https://github.com/tnhu/jsface | ||
* | ||
* Copyright (c) 2009-2012 Tan Nhu | ||
* Licensed under MIT license (https://github.com/tannhu/jsface/blob/master/MIT-LICENSE.txt) | ||
* Version: 2.1.0 | ||
* Licensed under MIT license (https://github.com/tnhu/jsface/blob/master/LICENSE.txt) | ||
*/ | ||
@@ -15,28 +14,33 @@ (function(context) { | ||
isFunction = jsface.isFunction, | ||
readyFns = []; | ||
readyFns = [], | ||
readyCount = 0; | ||
Class.plugins.$ready = function(clazz, parent, api) { | ||
var r = api.$ready, count = 0, len = parent ? parent.length : 0, pa, entry; | ||
var r = api.$ready, | ||
len = parent ? parent.length : 0, | ||
count = len, | ||
pa, i, entry; | ||
// in an environment where there are a lot of class creating/removing (rarely) | ||
// this implementation might cause a leak (saving pointers to clazz and $ready) | ||
for (entry in readyFns) { | ||
while (len--) { | ||
pa = parent[len]; | ||
while (len--) { | ||
for (i = 0; i < readyCount; i++) { | ||
entry = readyFns[i]; | ||
pa = parent[len]; | ||
if (pa === entry[0]) { | ||
entry[1].call(pa, clazz, api, parent); | ||
entry[1].call(pa, clazz, parent, api); | ||
count--; | ||
} | ||
if (count++ >= len ) { | ||
count = false; | ||
break; | ||
} | ||
if ( !count) { break; } | ||
} | ||
if ( !count) { break; } | ||
} | ||
// in an environment where there are a lot of class creating/removing (rarely) | ||
// this implementation might cause a leak (saving pointers to clazz and $ready) | ||
if (isFunction(r)) { | ||
r.call(clazz, clazz, api, parent); | ||
r.call(clazz, clazz, parent, api); | ||
readyFns.push([ clazz, r ]); | ||
readyCount++; | ||
} | ||
}; | ||
})(this); |
@@ -6,12 +6,12 @@ { | ||
"author" : "Tan Nhu <tnhu AT me . com>", | ||
"version" : "2.1.0", | ||
"version" : "2.1.1", | ||
"keywords" : [ "jsface", "JSFace", "OOP", "JavaScript OOP", "JavaScript Object Oriented Programming", "AOP", "Aspect Oriented Programming" ], | ||
"homepage" : "https://github.com/tannhu/jsface", | ||
"homepage" : "https://github.com/tnhu/jsface", | ||
"licenses" : [{ | ||
"type" : "MIT", | ||
"url" : "https://github.com/tannhu/jsface/blob/master/MIT-LICENSE.txt" | ||
"url" : "https://github.com/tnhu/jsface/blob/master/LICENSE.txt" | ||
}], | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "git://github.com/tannhu/jsface.git" | ||
"url" : "git://github.com/tnhu/jsface.git" | ||
}, | ||
@@ -18,0 +18,0 @@ "engines" : { |
![Benchmark result](https://lh5.googleusercontent.com/-2dQo8ttjn48/T2KVyppgd2I/AAAAAAAADQw/GvEpE5MIYUo/s956/Screen%2520Shot%25202012-03-15%2520at%25206.21.04%2520PM.png "Benchmark") | ||
[![Build Status](https://secure.travis-ci.org/tannhu/jsface.png?branch=master)](http://travis-ci.org/tannhu/jsface) | ||
# Features | ||
* Small footprint, no dependency, 0.7K minimized+gzip! | ||
* Super fast! See [benchmark](http://jsperf.com/oop-benchmark/6) | ||
* Super fast! See [benchmark](http://jsperf.com/oop-benchmark/6). | ||
* Work on both server and client side. | ||
* Support CommonJS. | ||
* Support singleton, mixin, private properties, Aspect Oriented Programming. | ||
* Support main, singleton, mixin, private properties, Aspect Oriented Programming. | ||
* Plugins mechanism to extend itself. | ||
@@ -82,2 +83,24 @@ | ||
## main | ||
JSFace supports a special method named main(). It works just similar to Java's main method. | ||
``` javascript | ||
Class({ | ||
constructor: function(name) { | ||
this.name = name; | ||
}, | ||
getName: function() { | ||
return this.name; | ||
}, | ||
main: function(Person) { // Class is passed to main() as its first argument | ||
var p = new Person("Rika"); | ||
p.getName(); // "Rika" | ||
} | ||
}); | ||
``` | ||
## Singleton class | ||
@@ -128,2 +151,4 @@ | ||
JSFace supports private static properties, meaning the properties are shared over instances. | ||
``` javascript | ||
@@ -130,0 +155,0 @@ var Person = Class(function() { |
var Foo = Class(function(){ | ||
// please note that privateCounter and privateEcho are | ||
// private static. They are shared over Foo's instances | ||
var privateCounter = 0; | ||
@@ -3,0 +5,0 @@ |
@@ -737,2 +737,27 @@ var context = this, | ||
test("Test public static void main ;-)", function() { | ||
var passed; | ||
var Person = Class({ | ||
constructor: function(name) { | ||
this.name = name; | ||
}, | ||
getName: function() { | ||
passed = true; | ||
return this.name; | ||
}, | ||
main: function(Person) { | ||
// Note that main has access to Person in its arguments only, not the person declared as var outside | ||
var p = new Person("Rika"); | ||
p.getName(); | ||
} | ||
}); | ||
ok(passed, "main method must be executed correctly"); | ||
equal(undefined, Person.main, "main must not bound to Person"); | ||
equal(undefined, Person.prototype.main, "main must not bound to Person.prototype"); | ||
}); | ||
// --------- PLUGINS --------- // | ||
@@ -739,0 +764,0 @@ |
@@ -13,5 +13,5 @@ var context = this, | ||
var Foo = Class({ | ||
$ready: function(clazz, api, parent) { | ||
$ready: function(clazz, parent, api) { | ||
notified = true; | ||
equal(this, clazz, "$ready works incorrectly"); | ||
equal(this, clazz, "clazz must be equal to this"); | ||
ok(isFunction(api.$ready), "$ready works incorrectly"); | ||
@@ -34,3 +34,3 @@ ok(isFunction(api.echo), "$ready works incorrectly"); | ||
var Foo = Class({ | ||
$ready: function(clazz, api, parent) { | ||
$ready: function(clazz, parent, api) { | ||
notified = true; | ||
@@ -37,0 +37,0 @@ |
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
437
0
119966
3359