![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
A JavaScript DSL to define objects in a fluent way.
npm install bau
var bau = require('bau');
Create a new instance to add modifiers.
var b = bau.create();
Define a modifier fn
on .prototype
and make it chainable, i.e. it will return this
in case fn
returns nothing.
bau.define('foo', function (name, delta) {
this.push(function (obj) {
obj[name] += delta;
});
});
var b = bau.create().foo('bar', 1);
var obj = b.apply({ bar: 2 });
obj.bar === 3;
Create a separate DSL inheriting all existing extensions. Modifications to the new DSL will not apply to its ancestor.
var bau2 = bau.fork();
Calls the given function with this
as first argument.
It is a shorthand for applying extensions.
bau.use(function (bau) {
// Define extensions here.
});
A shorthand for .create()
to provide a more concise fluent DSL.
bau.with.someExtension();
// vs
bau.create().someExtension();
Apply all modifiers in the order they were added to a given object and return that object.
Call #apply
on a new object created from the given prototype or null
if none is given.
Add a modifier function.
b.push(function (obj) {
obj.foo = 42;
});
var obj = b.apply({});
obj.foo === 42;
Bundled modifiers are only applied when importing via require('bau')
which will use a fork of require('bau/lib/bau')
.
Define ES5 getters and setters for the given names which are either given as multiple arguments or a single array.
The getters and setters are defined as non-enumerable, non-configurable, and non-writable.
If you only want getters or setters (but not both) use #getter
or #setter
respectively because getter and setter are defined via a single property which cannot be re-defined afterwards.
They simply delegate to regular methods whose name is determined by capitalizing a name's first character (String#toUpperCase
) and prefixing it with get
or set
respectively.
The reason for this approach is that overriding a method and accessing the overridden method with a different context (Function#call
or Function#apply
) is easy.
The same does not hold true for proper ES5 getters and setters which have to be accessed via a property descriptor's get
and set
properties in order to invoke Function#call
or Function#apply
to pass a different context to those functions.
b.accessor('foo');
var obj = b.create();
obj.foo;
// => obj.getFoo();
obj.foo = 42;
// => obj.setFoo(42);
Define properties using Object.defineProperties
.
b.define({
someConstant: {
value: 'bar'
}
});
var obj = b.create();
obj.someConstant === 'bar';
Similar to #accessor
but only defines getters.
b.getter('foo');
var obj = b.create();
obj.foo;
// => obj.getFoo();
Mixin the properties of a some object obj
using Object.defineProperty
and the individual property descriptors.
b.mixin({
someMethod: function () {
console.log('yada yada yada');
}
});
var obj = b.create();
obj.someMethod();
// => console.log('yada yada yada');
Override properties with the properties and the result of their respective functions in the given object. Overridden properties are made accessible as first argument passed to the function returning the overriding value. This argument is the overridden value when overriding an object's own property. When overriding a property inherited via the prototype chain, the argument will be a function delegating to the current property accessible on the prototype.
b.override({
hello: function (_super) {
return function () {
return _super.call(this) + ' Doe';
};
}
});
var obj = {
name: 'Jane',
hello: function () {
return 'Hello ' + this.name;
}
};
b.apply(obj);
obj.hello();
// => 'Hello Jane Doe';
Similar to #accessor
but only defines setters.
b.setter('foo');
var obj = b.create();
obj.foo = 42;
// => obj.setFoo(42);
Licensed under the AGPL 3.0.
FAQs
bau
The npm package bau receives a total of 0 weekly downloads. As such, bau popularity was classified as not popular.
We found that bau demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.